why doesn't this work even though the strings match [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
games=[]
file=open("egames.txt",'r')
for game in file:
games.append(game)
file.close()
print("All games made by Rockstar Games")
for game in games:
currentline=game.split(",")
publisher=currentline[5]
if publisher=="Rockstar Games":
print(currentline[0],currentline[1])
I dont get any errors i just get nothing being printed] with Rockstar Games.The actual Text file

Lines read from a file iterator end with newline characters. You should strip them as part of the normalization:
for game in file:
games.append(game.rstrip())

I'm guessing that the issue is the trailing newline characters, which are invisible to your eye. Try stripping off any white space:
publisher = currentline[5].strip()

Related

Python program for encryption string. a=z, b=y, c=x etc in lower case [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 days ago.
Improve this question
The whitespace should be replaced with a 'dollar' sign.
Keep the punctuation marks unchanged.
Note: Convert the given input sentence into lowercase before encrypting.
The final output should be lowercase.
input = Hello World
expected_output = svool$dliow

Printing Output Causes Split Lines Half of The Time [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to automate a task which requires using a specific URL which changes depending on the site location. The site locations are already loaded into a .txt file with no spaces at the beginning nor end of each line. The script runs down the list and changes the variable in the URL to match the line it is currently on then saves it to a file to be used later.
The issue I am having is that the script seems to split the outputted lines nearly every time which breaks my ability to read the lines in the next program.
Sample output:
https://picklepickle.com/api/11/networks/12312313154564654
/fickle/toast/3
https://picklepickle.com/api/11/networks/12312313154564655
/fickle/toast/3
https://picklepickle.com/api/11/networks/12312313154564656/fickle/toast/3
https://picklepickle.com/api/11/networks/12312313154564657/fickle/toast/3
This is a small snippet as the original file has nearly 100 lines in it.
Why does the code output the lines in such a weird way? How do I fix it so that it outputs each URL into one neat line?
raw = open("NetIDs.txt")
networks = raw.readlines()
for line in networks:
for i in line:
f = open("Checker.txt", "a+")
f.write('https://picklepickle.com/api/11/networks/{}/fickle/toast/3\n'.format(line))
f.close()
Maybe try stripping your raw text- readlines() will return \n (newline characters), as well.
...
f.write('https://picklepickle.com/api/11/networks/{}/fickle/toast/3\n'.format(line.strip()))
...
The .strip() will remove characters like \n,\t, and more.

Whem i output this code nothing comes out someone explain? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have found the following code on the internet and it is meant to output the positions of the words in the list:
mylist
But it is not working, here is the code:
mylist="example string with spaces"
sentencelist=[]
for z in mylist.split(" "):
sentencelist.append(z)
wordlist=[]
for z in range(len(sentencelist)):
if sentencelist[z] not in wordlist:
wordlist.append(sentencelist[z])
wordpositions=[]
for i in range (len(sentencelist)):
for o in range(len(wordlist)):
if sentencelist[i]==wordlist[o]:
wordpositions.append(o+1)
wordlist=str(wordlist)
wordpositions=str(wordpositions)
inputFile=open("sentence.txt","w")
inputFile.write(wordlist)
inputFile.write("\n")
inputFile.write(wordpositions)
inputFile.close()
No error message comes out but it also doesn't work. Can someone expalin
For me, the script does successfully write a file sentence.txt with the content of wordlist and wordpositions.
If you want to have these printed out to console, as well, add:
print(wordlist)
print(wordpositions)

url.strip()+' - CatchAllError' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am try to run this program as it start run but while running it's create error regrading CatchAllError . I want output as ' Pass ' But its not please help. Thanks
if line:
msg = url.strip()+' - CatchAllError'
print msg
with open("log_Error.txt", "a") as log:
log.write(msg+"\n")
else:
pass
You can see my whole program at https://ghostbin.com/paste/ypdmd.
You can see that if condition should be pass but it's not. To include target list go to https://ghostbin.com/paste/pjuox and download target list and other information.
You are mixing tabs and spaces. This confuses Python* and may cause unexpected behavior.
Use only tabs or only spaces, not both. Spaces is preferable.
(*well, not really. Python knows exactly how to handle tabs; it just does so in a way that is very surprising to most users. In particular, one tab is not equivalent to 4 spaces, or 8, or whatever it looks like in your text editor. See 2.1.8 - Indentation for more information.)

Strip tabs only at the end of line? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a huge text file, each line has a tab-delimited string. I need to keep all tabs apart from those at the end of each line. I need to keep the carriage return. Any ideas?
I've tried everything on these answers:
How to trim whitespace (including tabs)?
Trimming a string in Python
Strip spaces/tabs/newlines - python
as well as others I've now closed the tabs on.
Just use a regular expression
>>> import re
>>> s="1\t2\t3\t\t\n"
>>> s2=re.sub('\t+\n','\n',s)
>>> s2
'1\t2\t3\n'

Categories