error

2021-01-27 Thread Maziar Ghasemi
Hi
i`m use eric6 to python 3.9.1 . when open eric see this:
Warning: translation file 'git_en_US' could not be loaded.
Using default.
and when i try to do repair`s python I see:
"C:/user/mazya/AppData/Local/programs/python/python39/python39.dll
Verify that you have access to that directory."
Please advise me how to resolve this error
-- 
mazyar ghasemi
MS student of Razi university
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Chris Green
Skip Montanaro  wrote:
> CW> How do you troubleshooting/debugging in Python?
> 
> GE> Mostly I read exception trace and read the code and think about it.
> GE> If that doesn't work, I add some print() or syslog() calls.
> 
> CW> I know hardcore computer scientists would tell me about Python debugger.
> 
> GE> I've been writing Python for 20+ years. I've never tried a debugger.
> 
> Agree with Grant on these points. I certainly use gdb to debug C code
> (like the interpreter), but for Python code, tracebacks and print
> statements pretty much take care of things. I know pdb has been around
> for a long while and many people like IDEs, but I've not generally
> found them all that useful. I'm stuck in the 90s I guess.
> 
Me too! :-)

I tend to use multiple terminal windows so I have the code being
edited in one window, run the code in another window and sometimes a
third window for looking at configuration etc.

Add print statement etc. for debugging.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Chris Angelico
On Wed, Jan 27, 2021 at 8:21 PM Chris Green  wrote:
>
> Skip Montanaro  wrote:
> > CW> How do you troubleshooting/debugging in Python?
> >
> > GE> Mostly I read exception trace and read the code and think about it.
> > GE> If that doesn't work, I add some print() or syslog() calls.
> >
> > CW> I know hardcore computer scientists would tell me about Python debugger.
> >
> > GE> I've been writing Python for 20+ years. I've never tried a debugger.
> >
> > Agree with Grant on these points. I certainly use gdb to debug C code
> > (like the interpreter), but for Python code, tracebacks and print
> > statements pretty much take care of things. I know pdb has been around
> > for a long while and many people like IDEs, but I've not generally
> > found them all that useful. I'm stuck in the 90s I guess.
> >
> Me too! :-)
>

Me three :)

I'm of the opinion that everyone should get some experience with the
most fundamental form of debugging: trigger the problem with logging
active. Sometimes that means reproducing a known problem, other times
it means predicting an unknown problem and just always having some
useful logging. (That's why your boot sequence inevitably creates a
bunch of logs of various forms.)

IIDPIO: If In Doubt, Print It Out... just keep that console noisy
until you're certain the information won't help you.

Some problems are easy to reproduce. You figure out how to make it
happen, you adjust your code, you tinker. Sometimes the tinkering will
involve a debug harness (like pdb), other times it just requires a few
more print() calls, and either way, great! But other problems aren't.
Try debugging a weird issue with your web site that shows up only once
every two weeks (or worse), and only ever occurs once. You can't run
your web server in a debug harness because the problem simply doesn't
happen on your local computer. Your only option is to try to log more
stuff and wait for the problem to happen again...

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


imalib cant get From: adresses

2021-01-27 Thread Bischoop


I don't have much experience with imaplib and for a few days can't
manage to get properly, I followed also some tutorial but also met few
problems.
What I want is to get email addresses from emails I do have in gmail
inbox. The code below gets them but then pops an error.
When I change the part "for i in range()" as in commented line it gets
just the last email.

Anybody familiar here with imaplib? 


import getpass, imaplib
import email
from email.header import decode_header

M = imaplib.IMAP4_SSL('imap.gmail.com')
M.login(u, p)
M.select()
status, messages = M.select("INBOX")
di={}

# number of top emails to fetch
N = 100

# total number of emails
messages = int(messages[0])

for i in range(messages, messages-N,-1):
#for i in range(messages, N):
# fetch the email message by ID
res, msg = M.fetch(str(i), "(RFC822)")
for response in msg:
if isinstance(response, tuple):
# parse a bytes email into a message object
msg = email.message_from_bytes(response[1])


From, encoding = decode_header(msg.get("From"))[0]
if isinstance(From, bytes):
From = From.decode(encoding)
print("From:", From)
print(type(From))


print("="*100)
if '<'in From:
s = From.index('<')
d = From.index('>')
q = From[s + 1:d]
w = From[0:s - 1]
if q in di.values():
pass
else:
di[w] = q
else:
if q not in di.values():

b = sum(1 for key in di if key.startswith('Friend'))
di[f'Friend{b+1}']=From
# close the connection and logout
M.close()
M.logout()

print(di)
for i in di.keys():
if 'Friend' in i:
print(From,'\n',i,di[i])

b = sum(1 for key in di if key.startswith('Friend'))
print(b)

raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: FETCH command error: BAD [b'Could not parse command']

Process finished with exit code 1






-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread David Raymond
In regards to the various comments about adding in print() calls what I've 
found myself doing is to basically always use the logging module, and use 
logging.debug() for those.

Somewhere at the top of the script I'll have a line like...

DEBUG = False

...and when initializing the handler to stdout I'll do something like this...

toScreen = logging.StreamHandler(sys.stdout)
toScreen.setLevel(logging.DEBUG if DEBUG else logging.INFO)


That way I can sprinkle in

logging.debug("Some message here")

in various spots. If things are going wrong I can change DEBUG to True to see 
them on screen, and when I've fixed it I can just set DEBUG back to False. That 
way I don't have to try finding all those print() statements that were only 
there for debugging and comment them out or remove them.

As a bonus, if you also set a file logger for example with its level set to 
logging.DEBUG, then you can have those go into the log file without them 
cluttering the screen output.

As a side effect to using logging I found I also like having the timestamp 
automatically prepended to my output by the logger. I'd find myself checking in 
on something I left running in the background and thinking it's been on that 
step for "a while", but I have no idea how long "a while" really is. So the 
timestamps help quickly show "been stuck there for 3 hours" vs "just got to 
that step 3 seconds before I switched to its window"

I don't claim these are the best practices :) But figured I'd offer another 
take on it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Michael Torrie
On 1/26/21 10:19 PM, C W wrote:
> Traceback (most recent call last):
>File "/Users/Mike/Documents/Mike/main.py", line 95, in 
>   main()
>File "/Users/Mike/Documents/Mike/main.py", line 86, in main
>   args = get_feed()
>File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed
>   result = [PERSONatabase.get_person(raw_person) for raw_neo in
> raw_objects]
>File "/Users/Mike/Documents/Mike/main.py", line 32, in 
>   result = [NEODatabase.get_person(raw_person) for raw_neo in
> raw_objects]
>File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person
>   return PERSONDatabase(person['created_at'],
> KeyError: 'created_at'

The actual error is the last part, which is a KeyError on line 24.  A
key error usually is from a dictionary-like object and it means the
requested key is not found in that object.  In other words, this person
object has no "created_at" key.  Hope that makes sense.

I do not know why the code you posted refers to "employee" but the
traceback refers to "person."

In any case the trace back shows you what called what until the error
occurred. You can trace the execution of the code simply by following
it.  main() called get_feed() which set up a list comprehension, which
calls get_person() which is where the error is occurring.  I'm not
following the list comprehension stuff; I don't know why python is first
referring to PERSONatabase and then refers to NEODatabase.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread C W
Hi Cameron,
Yes, you are correct in all above. There's a mistake in my copy paste.
Thanks for pointing that out!

On Wed, Jan 27, 2021 at 12:58 AM Cameron Simpson  wrote:

> On 27Jan2021 00:19, C W  wrote:
> >Here's the code again, class should be called PERSONDatabase,
> >misspelled
> >earlier:
> >class PERSONDatabase:
> >   def __init__(self, id, created_at, name, attend_date, distance):
> >  self._id = id
> >  self.created_at = created_at
> >  self.name= name
> >  self.attend_date = attend_date
> >  self.distance = distance
>
> Here's you're setting attributes (which is a very normal thing to do).
>
> >   @classmethod
> >   def get_person(self, employee):
> >  return PERSONDatabase(employee['created_at'],
> >employee['id'],
> >employee['name'],
> >employee['attend_date'],
> >employee['distance'])
>
> I think this "employee" is called "person" in the code the traceback
> came from. It is better when these two things match.
>
> >The PERSONDatabase class is called from main. This is the trace back I got
> >from the VS code:
> >
> >Traceback (most recent call last):
> >   File "/Users/Mike/Documents/Mike/main.py", line 95, in 
> >  main()
> >   File "/Users/Mike/Documents/Mike/main.py", line 86, in main
> >  args = get_feed()
> >   File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed
> >  result = [PERSONatabase.get_person(raw_person) for raw_neo in
> >raw_objects]
> >   File "/Users/Mike/Documents/Mike/main.py", line 32, in 
> >  result = [NEODatabase.get_person(raw_person) for raw_neo in
> >raw_objects]
> >   File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person
> >  return PERSONDatabase(person['created_at'],
> >KeyError: 'created_at'
>
> Here's you're trying to index another object using a string, which seems
> to resemble the .created_at attribute in your PERSONDatabase object.
>
> I would presume from this that the "person" object at the bottom of the
> traceback is the "raw_person" called above it. But I do not see
> raw_person defined anywhere. Are you sure you didn't mean to pass
> "raw_neo" instead of "raw_person"? That would be more normal, since
> you're iterating over "raw_objects".
>
> Cheers,
> Cameron Simpson 
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


asyncio: Gather over growing list of tasks

2021-01-27 Thread Justin Paston-Cooper
Hello,

Let's say I have a loop where at each iteration, a task which makes an
HTTP request to some endpoint is generated, and then the loop sleeps
for n seconds. These tasks may throw exceptions.

I can call asyncio.gather on these tasks once the loop has finished,
but I actually want to stop the loop immediately if an exception is
thrown.

Is there a solution that would allow me to stop this loop as soon as
an exception is thrown by any of these request tasks?

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


IDE tools to debug in Python?

2021-01-27 Thread flaskee via Python-list


While print() is groovy and all,
if anyone runs across a non-pdb python debugger (standalone or IDE-based)
please let me know.

I too was blessed with IDE-based debugging (in the 90's!)
 * where you can set break point(s);
 * have the program stop right before a suspected failure point;
 * check the contents of ALL variables, and choose whether to restart;
 * or skip a few lines before restarting;
 * or change a variable (hot, move back a few lines and restart, etc.
 * Some, would even let you alter the code a bit before restarting.

I too, miss this.


Hopefully I did not miss someone mentioning
such a python tool in the prior thread.

Thanks!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread C W
For learning purposes, here's the files:
https://www.dropbox.com/sh/a3iy40rcvib4uvj/AAADmlM2i6NquWC1SV0nZfnDa?dl=0

Yes, you are correct about "employee" and "person" discrepancies. For now,
the list comprehension is where I get stuck.

I'd like to know how the experts on here are approaching and debugging
this.

Bonus if no debugger or breakpoint. Just the good ol' run the function and
evaluate/print output for problems.

Thanks so much,

Mike

On Wed, Jan 27, 2021 at 10:53 AM Michael Torrie  wrote:

> On 1/26/21 10:19 PM, C W wrote:
> > Traceback (most recent call last):
> >File "/Users/Mike/Documents/Mike/main.py", line 95, in 
> >   main()
> >File "/Users/Mike/Documents/Mike/main.py", line 86, in main
> >   args = get_feed()
> >File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed
> >   result = [PERSONatabase.get_person(raw_person) for raw_neo in
> > raw_objects]
> >File "/Users/Mike/Documents/Mike/main.py", line 32, in 
> >   result = [NEODatabase.get_person(raw_person) for raw_neo in
> > raw_objects]
> >File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person
> >   return PERSONDatabase(person['created_at'],
> > KeyError: 'created_at'
>
> The actual error is the last part, which is a KeyError on line 24.  A
> key error usually is from a dictionary-like object and it means the
> requested key is not found in that object.  In other words, this person
> object has no "created_at" key.  Hope that makes sense.
>
> I do not know why the code you posted refers to "employee" but the
> traceback refers to "person."
>
> In any case the trace back shows you what called what until the error
> occurred. You can trace the execution of the code simply by following
> it.  main() called get_feed() which set up a list comprehension, which
> calls get_person() which is where the error is occurring.  I'm not
> following the list comprehension stuff; I don't know why python is first
> referring to PERSONatabase and then refers to NEODatabase.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread Michał Jaworski
PyCharm has all these debugging capabilities and there is a community edition 
that you can use for free. If you earn for the living with Python it is worth 
investing in professional edition though. 

Michał Jaworski

> Wiadomość napisana przez flaskee via Python-list  w 
> dniu 27.01.2021, o godz. 19:32:
> 
> 
> While print() is groovy and all,
> if anyone runs across a non-pdb python debugger (standalone or IDE-based)
> please let me know.
> 
> I too was blessed with IDE-based debugging (in the 90's!)
> * where you can set break point(s);
> * have the program stop right before a suspected failure point;
> * check the contents of ALL variables, and choose whether to restart;
> * or skip a few lines before restarting;
> * or change a variable (hot, move back a few lines and restart, etc.
> * Some, would even let you alter the code a bit before restarting.
> 
> I too, miss this.
> 
> 
> Hopefully I did not miss someone mentioning
> such a python tool in the prior thread.
> 
> Thanks!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


How to accept argparse.log_level parameter and propagate its value to all other modules

2021-01-27 Thread Zoran
In the same folder I have three files: main.py, app_logger.py and mymodule.py 
with their contents:

# main.py
import argparse
import app_logger
import mymodule
import logging

logger = app_logger.get_logger(__name__)

def log_some_messages():
logger.debug(f'{__name__} - debug message')
logger.info(f'{__name__} - info message')
logger.warning(f'{__name__} - warning message')

if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Script for executing data 
quality checks.")
parser.add_argument("--log-level", default='info', choices=['notset', 
'debug', 'info', 'warning', 'error', 'critical'], help="set log level")
args = parser.parse_args()

logger.setLevel(eval(f"logging.{args.log_level.upper()}"))

log_some_messages()
mymodule.log_some_messages()


#mymodule.py
import logging

from script_logging import app_logger

logger = app_logger.get_logger(__name__)


def log_some_messages():
logger.debug(f'{__name__} - debug message')
logger.info(f'{__name__} - info message')
logger.warning(f'{__name__} - warning message')


#app_logger.py
import logging

_log_format = f"%(asctime)s - [%(levelname)s] - %(name)s - 
(%(filename)s).%(funcName)s(%(lineno)d) - %(message)s"
_log_level = logging.DEBUG

def get_stream_handler():
stream_handler = logging.StreamHandler()
stream_handler.setLevel(_log_level)
stream_handler.setFormatter(logging.Formatter(_log_format))
return stream_handler

def get_logger(name):
logger = logging.getLogger(name)
logger.setLevel(_log_level)
logger.addHandler(get_stream_handler())
return logger

When I run it with main.py --log-level debug I get the following output:

2021-01-25 13:21:01,151 - [DEBUG] - __main__ - (main.py).log_some_messages(10) 
- __main__ - debug message
2021-01-25 13:21:01,151 - [INFO] - __main__ - (main.py).log_some_messages(11) - 
__main__ - info message
2021-01-25 13:21:01,152 - [WARNING] - __main__ - 
(main.py).log_some_messages(12) - __main__ - warning message
2021-01-25 13:21:01,152 - [DEBUG] - mymodule - 
(mymodule.py).log_some_messages(10) - mymodule - debug message
2021-01-25 13:21:01,152 - [INFO] - mymodule - 
(mymodule.py).log_some_messages(11) - mymodule - info message
2021-01-25 13:21:01,152 - [WARNING] - mymodule - 
(mymodule.py).log_some_messages(12) - mymodule - warning message

which is OK. If I change --log-level parameter to 'warning', than output is the 
following:

2021-01-25 13:22:12,760 - [WARNING] - __main__ - 
(main.py).log_some_messages(12) - __main__ - warning message
2021-01-25 13:22:12,760 - [DEBUG] - mymodule - 
(mymodule.py).log_some_messages(10) - mymodule - debug message
2021-01-25 13:22:12,761 - [INFO] - mymodule - 
(mymodule.py).log_some_messages(11) - mymodule - info message
2021-01-25 13:22:12,761 - [WARNING] - mymodule - 
(mymodule.py).log_some_messages(12) - mymodule - warning message

As you can see, in main.py log level is set correctly, but in mymodule.py it is 
not.

How to accept argparse.log_level parameter in if __name__ == '__main__': and 
propagate its value to all other modules?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread C W
I'm not expert in Python, but I sure tried many IDEs to kick off Python
programming.

I started with PyCharm, but I had a problem with it constantly scanning the
background, even after I turned that feature off.

My favorite (I'm using now) is VS Code with Python extension, it's very
light. Recently also started background scanning, but that's generally done
in 30 seconds.

On Wed, Jan 27, 2021 at 1:51 PM Michał Jaworski  wrote:

> PyCharm has all these debugging capabilities and there is a community
> edition that you can use for free. If you earn for the living with Python
> it is worth investing in professional edition though.
>
> Michał Jaworski
>
> > Wiadomość napisana przez flaskee via Python-list 
> w dniu 27.01.2021, o godz. 19:32:
> >
> > 
> > While print() is groovy and all,
> > if anyone runs across a non-pdb python debugger (standalone or IDE-based)
> > please let me know.
> >
> > I too was blessed with IDE-based debugging (in the 90's!)
> > * where you can set break point(s);
> > * have the program stop right before a suspected failure point;
> > * check the contents of ALL variables, and choose whether to restart;
> > * or skip a few lines before restarting;
> > * or change a variable (hot, move back a few lines and restart, etc.
> > * Some, would even let you alter the code a bit before restarting.
> >
> > I too, miss this.
> >
> >
> > Hopefully I did not miss someone mentioning
> > such a python tool in the prior thread.
> >
> > Thanks!
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Dietmar Schwertberger

On 27.01.2021 01:52, Skip Montanaro wrote:

Agree with Grant on these points. I certainly use gdb to debug C code
(like the interpreter), but for Python code, tracebacks and print
statements pretty much take care of things.

I thought so for the first 12 year of using Python.
For the last 12 years I have been using an IDE/debugger with built-in 
console.


It boosted productivity by at least a factor of two.


Sometimes "python -i ..." and "import pdb" is good enough, being able to 
inspect variables after an exception.

I have the impression that pdb as post mortem debugger is not well known...

Regards,

Dietmar


--
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread Dietmar Schwertberger

On 27.01.2021 20:07, C W wrote:

I'm not expert in Python, but I sure tried many IDEs to kick off Python
programming.

I started with PyCharm, but I had a problem with it constantly scanning the
background, even after I turned that feature off.

My favorite (I'm using now) is VS Code with Python extension, it's very
light. Recently also started background scanning, but that's generally done
in 30 seconds.


There's also Wing IDE (Pro). The best is to try at least PyCharm and 
Wing IDE (Pro) and maybe one or more of the others.


Besides the debugger experience from the 90's please note that stepping 
through a program is not the most valuable feature of the Python debuggers:
Python is an interactive language. You can develop a lot while working 
on a Python console. Then copy and paste into a program.


Especially for hardware control, network programming and GUI development 
I find that the most valuable feature of Python.
(Maybe you have used Forth in the 90s as well, then you will know this 
feature.)


The better debuggers have a built-in console.
See here for a screenshot of Wing's debug console exploring GUI code: 
http://wxglade.sourceforge.net/docs/_images/Calculator_Debugger.png


Regards,

Dietmar



--
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread flaskee via Python-list
" also started background scanning, but that's generally done in 30 seconds."

Do we know what PyCharm is background scanning for?
Do we know what VS Code is scanning for?

I've been leery of VS* things since 2013, when Microsoft (secretly) changed 
their VS compiler, so that every single .exe, .dll, etc that was compiled; 
included a tiny API call, that dialed back to Microsoft. Even a Hello-World.exe 
would get this telemetry API embedded. So, if you distributed executables -- MS 
knew right where they went to, when the user ran them.

There was "outrage" when Microsoft was finally caught; and they backed off of 
this in the next version (I do not know if they've snuck it in again or not). 
But it did not raise my confidence in tools from Microsoft all that much.

I love Python.
I just want to add a real debugger ;-)

Sent with [ProtonMail](https://protonmail.com) Secure Email.

‐‐‐ Original Message ‐‐‐
On Wednesday, January 27, 2021 2:07 PM, C W  wrote:

> I'm not expert in Python, but I sure tried many IDEs to kick off Python 
> programming.
>
> I started with PyCharm, but I had a problem with it constantly scanning the 
> background, even after I turned that feature off.
>
> My favorite (I'm using now) is VS Code with Python extension, it's very 
> light. Recently also started background scanning, but that's generally done 
> in 30 seconds.
>
> On Wed, Jan 27, 2021 at 1:51 PM Michał Jaworski  wrote:
>
>> PyCharm has all these debugging capabilities and there is a community 
>> edition that you can use for free. If you earn for the living with Python it 
>> is worth investing in professional edition though.
>>
>> Michał Jaworski
>>
>>> Wiadomość napisana przez flaskee via Python-list  w 
>>> dniu 27.01.2021, o godz. 19:32:
>>>
>>> 
>>> While print() is groovy and all,
>>> if anyone runs across a non-pdb python debugger (standalone or IDE-based)
>>> please let me know.
>>>
>>> I too was blessed with IDE-based debugging (in the 90's!)
>>> * where you can set break point(s);
>>> * have the program stop right before a suspected failure point;
>>> * check the contents of ALL variables, and choose whether to restart;
>>> * or skip a few lines before restarting;
>>> * or change a variable (hot, move back a few lines and restart, etc.
>>> * Some, would even let you alter the code a bit before restarting.
>>>
>>> I too, miss this.
>>>
>>>
>>> Hopefully I did not miss someone mentioning
>>> such a python tool in the prior thread.
>>>
>>> Thanks!
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: imalib cant get From: adresses

2021-01-27 Thread Bischoop
On 2021-01-27, Bischoop  wrote:


Solved using IMAP4.uid.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread Grant Edwards
On 2021-01-27, C W  wrote:
> I'm not expert in Python, but I sure tried many IDEs to kick off Python
> programming.
>
> I started with PyCharm, but I had a problem with it constantly scanning the
> background, even after I turned that feature off.

What is it scanning?

> My favorite (I'm using now) is VS Code with Python extension, it's very
> light. Recently also started background scanning, but that's generally done
> in 30 seconds.

Same question, what is it scanning?

--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread C W
I don't know exactly, but it shows as inspection on the bottom left corner.

I believe it's indexing in the background.

On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards 
wrote:

> On 2021-01-27, C W  wrote:
> > I'm not expert in Python, but I sure tried many IDEs to kick off Python
> > programming.
> >
> > I started with PyCharm, but I had a problem with it constantly scanning
> the
> > background, even after I turned that feature off.
>
> What is it scanning?
>
> > My favorite (I'm using now) is VS Code with Python extension, it's very
> > light. Recently also started background scanning, but that's generally
> done
> > in 30 seconds.
>
> Same question, what is it scanning?
>
> --
> Grant
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread C W
I meant bottom right corner, not left. opps!

On Wed, Jan 27, 2021 at 3:36 PM C W  wrote:

> I don't know exactly, but it shows as inspection on the bottom left corner.
>
> I believe it's indexing in the background.
>
> On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards 
> wrote:
>
>> On 2021-01-27, C W  wrote:
>> > I'm not expert in Python, but I sure tried many IDEs to kick off Python
>> > programming.
>> >
>> > I started with PyCharm, but I had a problem with it constantly scanning
>> the
>> > background, even after I turned that feature off.
>>
>> What is it scanning?
>>
>> > My favorite (I'm using now) is VS Code with Python extension, it's very
>> > light. Recently also started background scanning, but that's generally
>> done
>> > in 30 seconds.
>>
>> Same question, what is it scanning?
>>
>> --
>> Grant
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread Paul Bryan via Python-list
My experience with IntelliJ (related to PyCharm): it scans all source
files in the project, compiles them, graphs all dependencies, compiles
those (if necessary) or inspects their class bytecode, and so on to
build a full graph in memory to support showing errors in real time
(highlighting in source) and autocomplete when user is typing. In my
experience, it's heavyweight, and creates more reliance on the features
of an IDE than I feel is healthy (IDE becomes a crutch). I suspect
PyCharm is doing much of the same.

On Wed, 2021-01-27 at 15:36 -0500, C W wrote:
> I don't know exactly, but it shows as inspection on the bottom left
> corner.
> 
> I believe it's indexing in the background.
> 
> On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards
> 
> wrote:
> 
> > On 2021-01-27, C W  wrote:
> > > I'm not expert in Python, but I sure tried many IDEs to kick off
> > > Python
> > > programming.
> > > 
> > > I started with PyCharm, but I had a problem with it constantly
> > > scanning
> > the
> > > background, even after I turned that feature off.
> > 
> > What is it scanning?
> > 
> > > My favorite (I'm using now) is VS Code with Python extension,
> > > it's very
> > > light. Recently also started background scanning, but that's
> > > generally
> > done
> > > in 30 seconds.
> > 
> > Same question, what is it scanning?
> > 
> > --
> > Grant
> > 
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread J. Pic
Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans,
eclipse, pdbpp...

Also see: https://wiki.python.org/moin/PythonDebuggingTools

"Changing a variable" -> that's basically evaluating code ? -> supported in
all debuggers I suppose
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: imalib cant get From: adresses

2021-01-27 Thread Barry Scott
Sigh you use a damaged email address for reply does not work.

> On 27 Jan 2021, at 14:30, Bischoop  wrote:
> 
> 
> I don't have much experience with imaplib and for a few days can't
> manage to get properly, I followed also some tutorial but also met few
> problems.
> What I want is to get email addresses from emails I do have in gmail
> inbox. The code below gets them but then pops an error.
> When I change the part "for i in range()" as in commented line it gets
> just the last email.
> 
> Anybody familiar here with imaplib? 

You have assumed that message ID are integers and in order.
Where as they are assigned by the IMAP server and are not in order.
I'm not even sure that they need to be integers.

You need to search the for the messages you want to get back a list of msg_id's.

The you can use the loop over the msg id doing operations on them.

After you M.select() call M.search() with appropriate params.
search is very powerful and will get you only the messages you are interested 
in.

Here is a fragment of some of my code to show the idea:

   folder_info = self.server.select_folder( folder, readonly=True )
   msg_ids = self.server.search( ['ALL'] )
   print( msg_ids )

   all_msg_info = self.server.fetch( msg_ids, ['FLAGS','ENVELOPE'] )
   for msg_id in all_msg_info:
   msg_info = all_msg_info[ msg_id ]
   print( '%-40s %s %s' % (msg_info[b'FLAGS'], 
msg_info[b'ENVELOPE'].date, msg_info[b'ENVELOPE'].subject) )

Barry

> 
> 
> import getpass, imaplib
> import email
> from email.header import decode_header
> 
> M = imaplib.IMAP4_SSL('imap.gmail.com')
> M.login(u, p)
> M.select()
> status, messages = M.select("INBOX")
> di={}
> 
> # number of top emails to fetch
> N = 100
> 
> # total number of emails
> messages = int(messages[0])
> 
> for i in range(messages, messages-N,-1):
> #for i in range(messages, N):
>   # fetch the email message by ID
>   res, msg = M.fetch(str(i), "(RFC822)")
>   for response in msg:
>   if isinstance(response, tuple):
>   # parse a bytes email into a message object
>   msg = email.message_from_bytes(response[1])
> 
> 
>   From, encoding = decode_header(msg.get("From"))[0]
>   if isinstance(From, bytes):
>   From = From.decode(encoding)
>   print("From:", From)
>   print(type(From))
> 
> 
>   print("="*100)
>   if '<'in From:
>   s = From.index('<')
>   d = From.index('>')
>   q = From[s + 1:d]
>   w = From[0:s - 1]
>   if q in di.values():
>   pass
>   else:
>   di[w] = q
>   else:
>   if q not in di.values():
> 
>   b = sum(1 for key in di if key.startswith('Friend'))
>   di[f'Friend{b+1}']=From
> # close the connection and logout
> M.close()
> M.logout()
> 
> print(di)
> for i in di.keys():
>   if 'Friend' in i:
>   print(From,'\n',i,di[i])
> 
> b = sum(1 for key in di if key.startswith('Friend'))
> print(b)
> 
>   raise self.error('%s command error: %s %s' % (name, typ, data))
> imaplib.error: FETCH command error: BAD [b'Could not parse command']
> 
> Process finished with exit code 1
> 
> 
> 
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to accept argparse.log_level parameter and propagate its value to all other modules

2021-01-27 Thread Peter Otten

On 27/01/2021 20:04, Zoran wrote:

In the same folder I have three files: main.py, app_logger.py and mymodule.py 
with their contents:

# main.py
import argparse
import app_logger
import mymodule
import logging

logger = app_logger.get_logger(__name__)

def log_some_messages():
 logger.debug(f'{__name__} - debug message')
 logger.info(f'{__name__} - info message')
 logger.warning(f'{__name__} - warning message')

if __name__ == '__main__':
 parser = argparse.ArgumentParser(description="Script for executing data quality 
checks.")
 parser.add_argument("--log-level", default='info', choices=['notset', 'debug', 
'info', 'warning', 'error', 'critical'], help="set log level")
 args = parser.parse_args()

 logger.setLevel(eval(f"logging.{args.log_level.upper()}"))

 log_some_messages()
 mymodule.log_some_messages()


#mymodule.py
import logging

from script_logging import app_logger

logger = app_logger.get_logger(__name__)


def log_some_messages():
 logger.debug(f'{__name__} - debug message')
 logger.info(f'{__name__} - info message')
 logger.warning(f'{__name__} - warning message')


#app_logger.py
import logging

_log_format = f"%(asctime)s - [%(levelname)s] - %(name)s - 
(%(filename)s).%(funcName)s(%(lineno)d) - %(message)s"
_log_level = logging.DEBUG

def get_stream_handler():
 stream_handler = logging.StreamHandler()
 stream_handler.setLevel(_log_level)
 stream_handler.setFormatter(logging.Formatter(_log_format))
 return stream_handler

def get_logger(name):
 logger = logging.getLogger(name)
 logger.setLevel(_log_level)
 logger.addHandler(get_stream_handler())
 return logger

When I run it with main.py --log-level debug I get the following output:

2021-01-25 13:21:01,151 - [DEBUG] - __main__ - (main.py).log_some_messages(10) 
- __main__ - debug message
2021-01-25 13:21:01,151 - [INFO] - __main__ - (main.py).log_some_messages(11) - 
__main__ - info message
2021-01-25 13:21:01,152 - [WARNING] - __main__ - 
(main.py).log_some_messages(12) - __main__ - warning message
2021-01-25 13:21:01,152 - [DEBUG] - mymodule - 
(mymodule.py).log_some_messages(10) - mymodule - debug message
2021-01-25 13:21:01,152 - [INFO] - mymodule - 
(mymodule.py).log_some_messages(11) - mymodule - info message
2021-01-25 13:21:01,152 - [WARNING] - mymodule - 
(mymodule.py).log_some_messages(12) - mymodule - warning message

which is OK. If I change --log-level parameter to 'warning', than output is the 
following:

2021-01-25 13:22:12,760 - [WARNING] - __main__ - 
(main.py).log_some_messages(12) - __main__ - warning message
2021-01-25 13:22:12,760 - [DEBUG] - mymodule - 
(mymodule.py).log_some_messages(10) - mymodule - debug message
2021-01-25 13:22:12,761 - [INFO] - mymodule - 
(mymodule.py).log_some_messages(11) - mymodule - info message
2021-01-25 13:22:12,761 - [WARNING] - mymodule - 
(mymodule.py).log_some_messages(12) - mymodule - warning message

As you can see, in main.py log level is set correctly, but in mymodule.py it is 
not.

How to accept argparse.log_level parameter in if __name__ == '__main__': and 
propagate its value to all other modules?


You just have to set the level in the root logger. The easiest way to
achieve that is to forget about your app_logger wrapper around logging
and call

logging.basicConfig(level=yourlevel, format=yourformat)

in  main.py and to create the loggers in main and mymodule

with

logger = logging.getLogger(__name__)


--
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread flaskee via Python-list

Thank you J. Pic.

Out of everything today,
(and given my priority is Python/Flask debugging)
it looks like Wing IDE is something to dig into.

Thanks


Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐
On Wednesday, January 27, 2021 4:09 PM, J. Pic  wrote:

> Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans,
> eclipse, pdbpp...
>
> Also see: https://wiki.python.org/moin/PythonDebuggingTools
>
> "Changing a variable" -> that's basically evaluating code ? -> supported in
>
> all debuggers I suppose
>
> 
>
> https://mail.python.org/mailman/listinfo/python-list


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Irv Kalb
On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list 
 wrote:
> 
> 
> 
>> On Jan 26, 2021, at 2:00 PM, C W  wrote:
>> 
>> Hello everyone,
>> 
>> I'm a long time Matlab and R user working on data science. How do you
>> troubleshooting/debugging in Python?
>> 
> 
> Another approach is to run the code in an IDE.  I happen to use Wing, but 
> that is a coincidence.  But almost ANY IDE will let you set a break point, 
> then single-step through your code starting at the break point and examine 
> the values of your variables at each step.  Sometimes this is an awfully big 
> hammer for what is a head-slapping mistake.  But it has never failed me.
> 
> 

I'm happy with the PyCharm IDE.  I created a video showing how to use the 
debugger in that environment.  It's available on YouTube here:

https://www.youtube.com/watch?v=cxAOSQQwDJ4 

Irv

-- 
https://mail.python.org/mailman/listinfo/python-list


For example: Question, moving a folder (T061RR7N1) containing a Specific file (ReadCMI), to folder: C:\\...\DUT0

2021-01-27 Thread Kevin M. Wilson via Python-list
for path, dir, files in os.walk(myDestinationFolder):
# for path, dir, files in os.walk(destfolder):
print('The path is %s: ', path)
print(files)
os.chdir(mySourceFolder)
if not os.path.isfile(myDestinationFolder + file):
#  if not os.path.isfile(destfolder + file):
print('The file is %s: ', file)
shutil.copytree(mySourceFolder, myDestinationFolder)
#  os.rename(path + '\\' + file, myDestinationFolder + file)
#  os.rename(path + '\\' + file, destfolder + file)
os.rename(path + '\\' + file, myDestinationFolder + file)
elif os.path.isfile(myDestinationFolder + file):
#  os.rename(path + '\\' + file, destfolder + file)
shutil.copytree(mySourceFolder, myDestinationFolder)
So I would very much appreciate your ideas on the above statements!Because...I 
think I've got the wrong function (os.path.isfile), when I should be (s/b) 
using a stepped approach!Note: program allows input of ID = T061RR7N1 (for 
example)1) find the folder containing "file": where folder = T061RR7N1, and 
file is "ReadCMI"; if TRUE, shutil.copytree C:\\...\T061RR7N1\ReadCMI (TO) 
C:\\...\DUT[?], where [?] is a num from 0 - 15.2) append to 
C:\\...\DUT[?]\T061RR7N1, which contains "ReadCMI"!

and would you mind telling me why this works (in every example I've found on 
the internet): r'C:\\anyfolder\\anyotherfolder\\'...what does the "r" signify? 
If it's 'read', why can't I use the 'a' for append?
KMW

"The only way to have experience is by having the experience"!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread C W
Great tutorial Irv, very simple with if-else example, gets the point
across.

My main takeaway from the discussion so far is that: you can't troubleshoot
Python without some kind of breakpoint or debugger.

I suppose I can't take the functional programming debugger style like C,
Matlab, or R, and apply it to a OOP language like Python.

On Wed, Jan 27, 2021 at 5:26 PM Irv Kalb  wrote:

> On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list <
> [email protected]> wrote:
> >
> >
> >
> >> On Jan 26, 2021, at 2:00 PM, C W  wrote:
> >>
> >> Hello everyone,
> >>
> >> I'm a long time Matlab and R user working on data science. How do you
> >> troubleshooting/debugging in Python?
> >>
> >
> > Another approach is to run the code in an IDE.  I happen to use Wing,
> but that is a coincidence.  But almost ANY IDE will let you set a break
> point, then single-step through your code starting at the break point and
> examine the values of your variables at each step.  Sometimes this is an
> awfully big hammer for what is a head-slapping mistake.  But it has never
> failed me.
> >
> >
>
> I'm happy with the PyCharm IDE.  I created a video showing how to use the
> debugger in that environment.  It's available on YouTube here:
>
> https://www.youtube.com/watch?v=cxAOSQQwDJ4  >
>
> Irv
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread J. Pic
You're most welcome flaskee, however I would recommend you try them all.
Thonny in particular because it distinguishes line from expression which I
believe is a unique feature.

Personally I have learned to love just pdb, and a whiteboard!

Le mer. 27 janv. 2021 à 23:03, flaskee  a écrit :

>
> Thank you J. Pic.
>
> Out of everything today,
> (and given my priority is Python/Flask debugging)
> it looks like Wing IDE is something to dig into.
>
> Thanks
>
>
> Sent with ProtonMail Secure Email.
>
> ‐‐‐ Original Message ‐‐‐
> On Wednesday, January 27, 2021 4:09 PM, J. Pic  wrote:
>
> > Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans,
> > eclipse, pdbpp...
> >
> > Also see: https://wiki.python.org/moin/PythonDebuggingTools
> >
> > "Changing a variable" -> that's basically evaluating code ? -> supported
> in
> >
> > all debuggers I suppose
> >
> > 
> >
> > https://mail.python.org/mailman/listinfo/python-list
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread 2QdxY4RzWzUUiLuE
On 2021-01-27 at 17:41:52 -0500,
C W  wrote:

> Great tutorial Irv, very simple with if-else example, gets the point
> across.

Disclaimer:  I did not watch the video.

> My main takeaway from the discussion so far is that: you can't
> troubleshoot Python without some kind of breakpoint or debugger.

I disagree.  :-)

Having spent a long time developing and debugging embedded systems (some
soft- or hard- real time), I believe that you can troubleshoot programs
(regardless of source language) without debuggers.  If a system can
generate output, then I (the programmer) can change that output, observe
the results, and figure out what's working and what's not.  Yes, some
systems are more painful than others, but yes, some debugging
environments are more painful than others, too.

A well placed call to print (they're not "print statements" anymore!)
can be much more enlightening and much faster than single stepping
through code in a debugger, and seeing the output from the same print
statement inside a loop can be much better than manually examining
variables iteration after iteration and trying to remember what the
value was before.

The best debugging tool, however, remains your brain.  Way before I add
a call to print or you set up your debugger, thinking about what went
wrong and where to look can solve the problems without resorting to
external tools.  :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread duncan smith
On 27/01/2021 22:41, C W wrote:
> Great tutorial Irv, very simple with if-else example, gets the point
> across.
> 
> My main takeaway from the discussion so far is that: you can't troubleshoot
> Python without some kind of breakpoint or debugger.
> 

[snip]

Really?

Duncan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread J. Pic
Also

- https://github.com/cool-RR/pysnooper
- https://github.com/andy-landy/traceback_with_variables
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Michael Torrie
On 1/27/21 11:42 AM, C W wrote:
> For learning purposes, here's the files:
> https://www.dropbox.com/sh/a3iy40rcvib4uvj/AAADmlM2i6NquWC1SV0nZfnDa?dl=0
> 
> Yes, you are correct about "employee" and "person" discrepancies. For now,
> the list comprehension is where I get stuck.
> 
> I'd like to know how the experts on here are approaching and debugging
> this.
> 
> Bonus if no debugger or breakpoint. Just the good ol' run the function and
> evaluate/print output for problems.

Like I said, the key is in the traceback.  It told you exactly what the
problem was. And seeing your full code I can now tell you why.  There is
no "created_at" field in the person dict (I noticed it's now called neo
in the code you just posted).  The dict is created directly from JSON
and there is no "created_at field anywhere in the JSON, which is why
you're getting that error.

I don't really understand much of the code you posted. There doesn't
seem to be any link between the MySQL database and the NEODatabase class
and instances.  Something is missing and it looks vaguely java-esque,
which may not be your best way to work in Python. I'm not sure what
you're trying to do so I can't really say much about it.

If you want to play with a database abstraction, there are several
libraries available, including SQLchemy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Alan Gauld via Python-list
On 27/01/2021 18:42, C W wrote:

> I'd like to know how the experts on here are approaching and debugging
> this.
> 
> Bonus if no debugger or breakpoint. Just the good ol' run the function and
> evaluate/print output for problems.

One option you may like and nobody seems to have mentioned
yet is to use the interactive prompt.

Simply run the program with the -i flag and the program will stay in the
interpreter at the >>> prompt. Similar to what you seem to be used to
doing in R...

>From there you can print the current value of variables, inspect objects
etc. I find it useful sometimes when I'm not on my desktop PC, although
usually I jump into winpdb or similar if I need that kind of support.

dubuggers and breakpoints combined with watchpoints are very powerful
tools and easy to learn. (Although I may be pre-disposed since my first
job after uni' was to white-box test 500K lines of C using a VAX command
line debugger in batch mode. I wrote over 100K lines of debugger commands!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE tools to debug in Python?

2021-01-27 Thread Alan Gauld via Python-list
On 27/01/2021 19:27, Dietmar Schwertberger wrote:

> Python is an interactive language. You can develop a lot while working 
> on a Python console. Then copy and paste into a program.

Absolutely, the humble interactive prompt is often overlooked
as a development tool. It's not as good as the "evaluate
expression" tool in the Smalltalk workspace, say, but it's close.

I habitually use 3 windows: - an editor, a shell command
line (to execute the code) and an interactive Python prompt.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Alan Gauld via Python-list
On 27/01/2021 23:04, [email protected] wrote:

> systems are more painful than others, but yes, some debugging
> environments are more painful than others, too.

Very true! but a good debugger is a godsend. Howevder...

> A well placed call to print (they're not "print statements" anymore!)
> can be much more enlightening and much faster than single stepping
> through code in a debugger,

If you are single stepping more than 2 or 3 lines then you
aren't using the debugger properly!

Use breakpoints(selected by brain power!) and watches. The watches
are like print statements but don;t modify the source code
(nothing to remove later!)

Anytime I find myself hitting the step button more that a few
times I know I'm not using the debugger effectively and rethink.

>  and seeing the output from the same print
> statement inside a loop can be much better than manually examining
> variables iteration after iteration and trying to remember what the
> value was before.

So don't do that, use the debugger. Most of them have conditional
breakpoints that will stop only when you need to.

> The best debugging tool, however, remains your brain.  

Amen to that, regardless of any software tool used.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: For example: Question, moving a folder (T061RR7N1) containing a Specific file (ReadCMI), to folder: C:\\...\DUT0

2021-01-27 Thread Jason Friedman
>
>
> for path, dir, files in os.walk(myDestinationFolder):
> # for path, dir, files in os.walk(destfolder):
> print('The path is %s: ', path)
> print(files)
> os.chdir(mySourceFolder)
> if not os.path.isfile(myDestinationFolder + file):
> #  if not os.path.isfile(destfolder + file):
> print('The file is %s: ', file)
> shutil.copytree(mySourceFolder, myDestinationFolder)
> #  os.rename(path + '\\' + file, myDestinationFolder + file)
> #  os.rename(path + '\\' + file, destfolder + file)
> os.rename(path + '\\' + file, myDestinationFolder + file)
> elif os.path.isfile(myDestinationFolder + file):
> #  os.rename(path + '\\' + file, destfolder + file)
> shutil.copytree(mySourceFolder, myDestinationFolder)
> So I would very much appreciate your ideas on the above
> statements!Because...I think I've got the wrong function (os.path.isfile),
> when I should be (s/b) using a stepped approach!Note: program allows input
> of ID = T061RR7N1 (for example)1) find the folder containing "file": where
> folder = T061RR7N1, and file is "ReadCMI"; if TRUE, shutil.copytree
> C:\\...\T061RR7N1\ReadCMI (TO) C:\\...\DUT[?], where [?] is a num from 0 -
> 15.2) append to C:\\...\DUT[?]\T061RR7N1, which contains "ReadCMI"!
>
> and would you mind telling me why this works (in every example I've found
> on the internet): r'C:\\anyfolder\\anyotherfolder\\'...what does the "r"
> signify? If it's 'read', why can't I use the 'a' for append?
>

A few answers and then a question ...

"r" in this context is a raw literal, see for example
https://www.journaldev.com/23598/python-raw-string.

And you probably don't need it. Python and Windows are happy with
"c:/path/to/file.txt" for a file path.
Some of your code might look end up looking like:
full_path = parent + "/" + file

See also the os.path.join method (
https://docs.python.org/3/library/os.path.html#os.path.join) and the
pathlib module (
https://docs.python.org/3/library/pathlib.html#module-pathlib).

If you truly want to move the folder, as opposed to copying it, you can use
shutil.move.

Does the target folder already exist? What is the rule for determining what
the target folder should be named?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to accept argparse.log_level parameter and propagate its value to all other modules

2021-01-27 Thread Zoran
Yes you are right. I changed the files:

# main.py
import argparse
import mymodule
import logging

logger = logging.getLogger(__name__)

def log_some_messages():
logger.debug(f'{__name__} - debug message')
logger.info(f'{__name__} - info message')
logger.warning(f'{__name__} - warning message')

if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Script for executing data 
quality checks.")
parser.add_argument("--log-level", default='info', choices=['notset', 
'debug', 'info', 'warning', 'error', 'critical'], help="set log level")
args = parser.parse_args()

log_level = logging.getLevelName(args.log_level.upper())
logging.basicConfig(level=log_level, format=f"%(asctime)s - [%(levelname)s] 
- %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s")
logger.setLevel(log_level)

log_some_messages()
mymodule.log_some_messages()

#mymodule.py
import logging

logger = logging.getLogger(__name__)


def log_some_messages():
logger.debug(f'{__name__} - debug message')
logger.info(f'{__name__} - info message')
logger.warning(f'{__name__} - warning message')

and everything works as it should.
I was milsleaded by this article 
https://towardsdatascience.com/8-advanced-python-logging-features-that-you-shouldnt-miss-a68a5ef1b62d

Thanks.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Grant Edwards
On 2021-01-27, C W  wrote:

> My main takeaway from the discussion so far is that: you can't troubleshoot
> Python without some kind of breakpoint or debugger.

How odd. I do it all the time.

--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Antoon Pardon




Op 27/01/21 om 05:17 schreef Dan Stromberg:

On Tue, Jan 26, 2021 at 8:13 PM Dan Stromberg  wrote:


On Tue, Jan 26, 2021 at 4:01 PM C W  wrote:


Hello everyone,

I'm a long time Matlab and R user working on data science. How do you
troubleshooting/debugging in Python?


I frequently read tracebacks and think about what's up in the code.

I also often add print functions or logging - empiricism often beats
theorizing when the problems are weird.

And once in a while I will use pudb - it's probably a pretty good fit for
a vim user like me, both being curses-based.  pdb is sad.  There are other
debuggers for Python:
https://wiki.python.org/moin/PythonDebuggingTools


BTW, there's a new tool I haven't tried yet, that sounds pretty
interesting, especially for newcomers: It's called "friendly traceback" and
can be found at https://pypi.org/project/friendly-traceback/

Oh, and of course google search is a terrific tool for deciphering error
messages.

I had a look at that and I think I still would prefer this recipe:
https://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/

--
https://mail.python.org/mailman/listinfo/python-list