Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have write this code to collect all data from twitter for cities like London. I have tried to write a code using python and it's give me this error on the line:
def process_or_store(tweet):
print(json.dumps(tweet)
What can I do to fix this?
Set a tabulator or spaces in front of this line (depends on what you used in the above lines), so it looks like:
def process_or_store(tweet):
print(json.dumps(tweet))
Remind, that python does not use {} to determine where a function starts and ends. A function must be in one indentation level instead.
You also forgot to close brackets at print().
Take the above definition, its syntax is correct.
Be aware of mixing up tabs and spaces (some editors manage this automatically, but if not, this can lead to errors that are not obvious)
Update:
def process_or_store(tweet):
print(json.dumps(tweet)
To be:
def process_or_store(tweet):
print(json.dumps(tweet))
and then delete your question
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
Here is the documentation: QTableWidget.sortItems
This is the function:
PySide6.QtWidgets.QTableWidget.sortItems(column[, order=Qt.AscendingOrder])
The following is my code:
self.notes_current_table_widget.sortItems(column[2, order=Qt.AscendingOrder])
PyCharm displays this as an error, when I try to run I get:
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
Syntax error is in regards to: order=Qt.AscendingOrder
I have tried on other QTableWidgets with the same issue. I have verified that the type is QTableWidget. I have updated all packages to the latest within the project. I have checked syntax of lines before and after.
I ran into this issue because I wanted to sort a dataframe and display the dataframe using a QTableWidget. df = dataframe. The dataframe is sorted until adding the df to the QTableWidget. That's when I looked at this QTableWidget.sortItems function. Any thoughts or ideas?
The docs say:
PySide6.QtWidgets.QTableWidget.sortItems(column[, order=Qt.AscendingOrder])
The square brackets here indicate that order is an optional argument, with default value Qt.AscendingOrder. You're not supposed to write the square brackets explicitly.
So, your code should probably look like this:
self.notes_current_table_widget.sortItems(column=2, order=Qt.AscendingOrder)
Or leave out order altogether, as you're using the default value anyway.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have problem with this if.
I found I can use in in if-statement.
if "log" in sys.argv[1:]
Syntax Error
If you don't show us the code surrounding the if-statement, we cannot know for sure what the problem is. If I were to make a guess however, I'd say you're missing a colon:
if "log" in sys.argv[1:]:
See the documentation for compound statements (like ifs):
Each clause header begins with a uniquely identifying keyword and ends with a colon
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
My point is that python has some predefined variables that you may have not even set, but still was given a value when you start off the shell. Say you ran the following code:
print (a)
Without even having defined variable "a" beforehand, it returned 0. Wherease, if you tried printing:
print(var1)
Would return an error because var1 was not defined. I did a bit of testing and found out the same goes for every other single character in python, print any of them out on the console and you will get the same result of 0.
The question I'd like to ask is that why are these characters given their own value beforehand? And are there special names for these predefined variables such as these? If I could know the name of these special variables, I could read upon some documentations about them.
There are no predefined variables in python.
print(a)
will return NameError: name 'a' is not defined as long as a has not been defined earlier.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I've been trying to make a simple program to save user data (such as a level or stat) and so far nothing I've found online works.
test = open("sketch_pad.py","w")
test.write("This is a test\nOr is it?")
test.close
This brings up an error, along the lines of "Not writable file" (despite the fact that it is a .py)
Either this, or it will erase all the data in the document "sketch_pad.py", and not write anything.
Close method should be called (f.close()). To avoid these kind of mistakes and ensure releasing resources on errors/exceptions you may consider using Python with statement, e.g.
with open("file.txt","w") as f:
f.write("data")
close is a method and should be called as such; f.close() is the correct syntax, currently you are omitting the brackets ().
test = open("sketch_pad.py","w")
test.write("This is a test\nOr is it?")
test.close() # you need these brackets
should work.
You can dodge these kinds of mistakes by using Python's with statement:
with open("myFile.txt", "w") as myFile:
myFile.write("data")
# no need for myFile.close(),
# it is called automatically.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
My code:
hi = glob.glob("hi/FEC[0-9][0-9][0-9][0-9][0-9]_[0-9].seq")
I'm using a glob module and I'm trying to get all the path file names but all it returns back is a empty list. I don't know why it keeps doing that. It worked before my code was accidentally erased.
[]
Regardless if the file isn't even there, it still gives me an empty list.
Update:
So the following files I have are
FEC00001_1.seq
FEC00002_1.seq
FEC00002_2.seq
and so on..
Update 2:
So it I just realized that it might have to do something with the wrong folder like you guys said.
Because right now, my script is in "folder1" and all the files I'm trying to access is in "folder2"
/mainfolder/folder1/script.py
/mainfolder/folder2/files im trying to access
glob.glob is done by using the os.listdir() and fnmatch.fnmatch() functions in concert. So it's important that you search at the right place.
Considering your file hierarchy:-
/mainfolder/folder1/script.py
/mainfolder/folder2/files im trying to access
try the following :-
hi = glob.glob("../folder2/FEC[0-9][0-9][0-9][0-9][0-9]_[0-9].seq")