Pycharm IDE

Mark Bourne nntp.mbourne at spamgourmet.com
Wed Apr 19 16:06:18 EDT 2023


Thomas Passin wrote:
> On 4/19/2023 1:27 AM, Kevin M. Wilson via Python-list wrote:
>> Ok, I got rid of the "print (f'"I am thinking of a number between 1 to 
>> {LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"),
> 
> I think you misunderstand several things at the same time here.
> 
> 1. These errors originate from syntax errors.  They are basically Python 
> errors.  It's possible that behind the scenes, PyCharm is running one or 
> another Python program to detect them, but they are errors in your 
> Python code.
> 
> 2. print() doesn't care whether you give it an f-string or not, because 
> a f-string is a string too.
> 
> 3. All strings need to be closed with the same kind of quote they 
> started with.  If one is not closed, then Python thinks the string is 
> supposed to continue, and - say- the final parenthesis of the print() 
> function looks like it is part of the string. So Python (or PyCharm) 
> notices that the closing parenthesis of the print() expression is missing.
> 
> 4. in an f-string, the expression in braces is evaluated and replaced by 
> its string value.  So if you try to do this
> 
> print('{LIMIT}')
> 
> then that will be printed as is with no  substitution - because it is 
> not an f-string.  So you will see "{LIMIT}" But you thought you were 
> going to see "42" (if LIMIT == 42, that is). OTOH,
> 
> print(f'{LIMIT})

^ I think this one should be:

print(f'{LIMIT}')

with the closing quote ;o)

> will substitute the string value of LIMIT before printing the string. 
> Both are legitimate but the first is not what you seem to want.
> 
> 5. As I posted earlier, you almost certainly do not need to add the "\n".
> 
> So, some suggestions:
> 
> - If you are having a problem with some piece of code, try to simplify 
> it down to the smallest bit that shows the problem.
> 
> - If you are having trouble with f-strings, then think about what you 
> want to achieve and look up information about f-strings with that in mind.
> 
> - If you are having trouble with the print statement, think what you 
> want it to display and look up information about the print function with 
> that in mind.
> 
> - If your tool - PyCharm in this case - is producing messages but you 
> don't understand why they are being produced, try to look up information 
> about how and when PyCharm produces error messages
> 
> Do you see a pattern here?
> 
> Also note that just because you don't see an error message does not mean 
> that the code is correct.  It may be correct from the point of view of 
> Python syntax but that doesn't mean that it will perform correctly nor 
> how you expect.
> 
>> and Pycharm stopped complaining about it... WHY??
>> Perplexed
>> "When you pass through the waters, I will be with you: and when 
>> you pass through the rivers, they will not sweep over you. When you 
>> walk through the fire, you will not be burned: the flames will not set 
>> you ablaze."
>> Isaiah 43:2
>>
>>      On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson 
>> via Python-list <python-list at python.org> wrote:
>>   print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had 
>> the impression that the format specifier 'f' was necessary for the 
>> print function, but the double quotes are for the string printed to 
>> the user, as a prompt!The Pycharm IDE is showing that it expects a 
>> single quotation mark or ')'! No error message is displayed.
>> Perplexed
>> "When you pass through the waters, I will be with you: and when 
>> you pass through the rivers, they will not sweep over you. When you 
>> walk through the fire, you will not be burned: the flames will not set 
>> you ablaze."
>> Isaiah 43:2
>>
>>      On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost 
>> <aapost at idontexist.club> wrote:
>>   On 4/18/23 19:18, Kevin M. Wilson wrote:
>>> Why complain about a 'comma', or a ')'???
>>>        print (f'"I am thinking of a number between 1 to {LIMIT}\n")
>>
>> my version says it expects ' first (to close the fstring)
>> then on a new line below it, it mentions the comma and )
>> I believe that is just showing you after ' it expects you to end the
>> print with ) as you have
>> or , to add additional arguments to print
> 


More information about the Python-list mailing list