This question already has answers here:
Long Int literal - Invalid Syntax?
(2 answers)
Closed 2 years ago.
I'm trying to convert a small file from Python2 to Python3.
This hex variable assignment is blocking me.
a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL
The error I'm receiving is:
a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL
^
SyntaxError: invalid syntax
Any suggestions?
Is there a problem if you remove the L? Is that not the value you expect?
>>> 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
115792089237316195423570985008687907853269984665640564039457584007908834671663
Wolfram alpha thinks that's the correct value!
Related
This question already has answers here:
Regular expression to stop at first match
(9 answers)
Python non-greedy regexes
(7 answers)
Closed 2 years ago.
Consider following code:
import re
mystring = "\enquote {aaa} a \enquote {bbb}"
text = re.sub(r"\\enquote \{(.+)\}", r"\1", mystring)
print(text)
is outputing:
"aaa} a \enquote {bbb"
but I am acrually trying to achieve output of:
"aaa a bbb"
What have I misunderstood?
Background: I am trying to do some simple conversion from LaTeX format to general text, for which I need to replace LaTeX commands, but retain raw text itself (and sometimes do also some actual replacing). So how can I do group capture in python?
This question already has answers here:
Python convert tuple to string
(5 answers)
Closed 2 years ago.
I would like to know how to convert an unknown number of arguments to a string. what I need to do is redirect the output of a function that is supposed to go to print() to a Qt QPlainTextEdit. since it only accepts strings, I need a way to convert the given arguments to a string.
basically what I am looking for is print() but instead of outputting to the terminal, the output is to a string.
If you have an array of elements you can do:
def print_foo(arr,count):
for i in range(0,int(count)):
print(str(arr[i]))
Basically, converting to string is - newstr = str(varriable)
This question already has answers here:
SYNTAX ERROR - Can't assign to operator in setting variables
(2 answers)
Closed 3 years ago.
I got a SyntaxError: can't assign to operator when I typed in a boolean. How can I fixed it? Below is the code that popped a error:
Super-Sport = False
^
SyntaxError: can't assign to operator
I expect it will run smoothly, but it didn't
Change Super-Sport to Super_Sport (or SuperSport etc). Python is interpreting the - as minus and causing your syntax error.
This question already has answers here:
How to use string.replace() in python 3.x
(9 answers)
Closed 5 years ago.
I am trying to write a program that replaces every 'a' for '&'.I am currently stumped and was wondering if someone could write it for me to get an idea of what it would look like. Thanks.
strw = "kabhi kabhi mery dil main khyaal aata hy"
print (strw.replace("a", "&"))
This question already has an answer here:
Nested arguments not compiling
(1 answer)
Closed 7 years ago.
I have a piece of code that looks completely fine,
def _change_id(self, model, path, it,(old_id, new_id)):
But whenever I try to run it in my terminal python returns, "SyntaxError: invalid syntax"
The use of the tuple parameter was removed in python 3.0. This caused more issues than it was worth. You can rewrite it this way:
def fun(p1, b_c, p2):
b, c = b_c
the parameter b_c was a tuple:
fun(1, (1, 2), 3)
Its called Removal of Tuple Parameter Unpacking (only in python3)
see http://legacy.python.org/dev/peps/pep-3113/
Apparently, tupple parameter unpacking was removed in python 3 as per this link here
Edit: #Yoav and #jonrsharpe beat me to it