Re: learning Python

2024-10-29 Thread Mats Wichmann via Python-list

On 10/27/24 16:51, o1bigtenor via Python-list wrote:

Greetings

There are mountains of books out there.

Any suggestions for documents for a just learning how to program and
starting with Python (3)?

Preference to a tool where I would be learning by doing - - - that
works well for me.

TIA


Frankly, the mountain of resources is so vast that none of us can have 
experience of more than a small fraction, and effective learning is a 
factor not only of the quality of the teacher/book/training course, but 
how it meshes with your own learning style.


If you like learn-by-doing, you might take a look at PyBites 
(https://pybit.es/). But they're by no means the only players in that space!



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


Re: learning Python

2024-10-29 Thread rbowman via Python-list
On Tue, 29 Oct 2024 16:05:53 -0600, Mats Wichmann wrote:

> Frankly, the mountain of resources is so vast that none of us can have
> experience of more than a small fraction, and effective learning is a
> factor not only of the quality of the teacher/book/training course, but
> how it meshes with your own learning style.

It isn't a beginners tutorial but at some point 'Python Distilled' is 
helpful.

https://www.dabeaz.com/python-distilled/

Usual disclaimer: i don't know Beazley and am not getting any kickback.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-29 Thread Jon Ribbens via Python-list
On 2024-10-29, Loris Bennett  wrote:
> Hi,
>
> With Python 3.9.18, if I do
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(config_file)
> print(config.sections())
>
> i.e try to read the configuration with the variable defined via 'with
> ... as', I get
>
>[]
>
> whereas if I use the file name directly
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(args.config_file)
> print(config.sections())
> I get 
>
>   ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 
> 'handler_consoleHandler', 'formatter_defaultFormatter']
>
> which is what I expect.
>
> If I print type of 'config_file' I get
>
>  
>
> whereas 'args.config_file' is just 
>
>  
>
> Should I be able to use the '_io.TextIOWrapper' object variable here?  If so 
> how?
>
> Here
>
>   https://docs.python.org/3.9/library/configparser.html
>
> there are examples which use the 'with open ... as' variable for writing
> a configuration file, but not for reading one.

As per the docs you link to, the read() method only takes filename(s)
as arguments, if you have an already-open file you want to read then
you should use the read_file() method instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-29 Thread MRAB via Python-list

On 2024-10-29 13:56, Loris Bennett via Python-list wrote:

Hi,

With Python 3.9.18, if I do

 try:
 with open(args.config_file, 'r') as config_file:
 config = configparser.ConfigParser()
 config.read(config_file)
 print(config.sections())

i.e try to read the configuration with the variable defined via 'with
... as', I get

[]

whereas if I use the file name directly

 try:
 with open(args.config_file, 'r') as config_file:
 config = configparser.ConfigParser()
 config.read(args.config_file)
 print(config.sections())
I get

   ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 
'handler_consoleHandler', 'formatter_defaultFormatter']

which is what I expect.

If I print type of 'config_file' I get

   

whereas 'args.config_file' is just

   

Should I be able to use the '_io.TextIOWrapper' object variable here?  If so 
how?

Here

   https://docs.python.org/3.9/library/configparser.html

there are examples which use the 'with open ... as' variable for writing
a configuration file, but not for reading one.

Cheers,

Loris

'config.read' expects a path or paths. If you give it a file handle, it 
treats it as an iterable. (It might be reading the line as paths of 
files, but I haven't tested it).


If you want to read from an open file, use 'config.read_file' instead.

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


Using 'with open(...) as ...' together with configparser.ConfigParser.read

2024-10-29 Thread Loris Bennett via Python-list
Hi,

With Python 3.9.18, if I do

try:
with open(args.config_file, 'r') as config_file:
config = configparser.ConfigParser()
config.read(config_file)
print(config.sections())

i.e try to read the configuration with the variable defined via 'with
... as', I get

   []

whereas if I use the file name directly

try:
with open(args.config_file, 'r') as config_file:
config = configparser.ConfigParser()
config.read(args.config_file)
print(config.sections())
I get 

  ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 
'handler_consoleHandler', 'formatter_defaultFormatter']

which is what I expect.

If I print type of 'config_file' I get

  

whereas 'args.config_file' is just 

  

Should I be able to use the '_io.TextIOWrapper' object variable here?  If so 
how?

Here

  https://docs.python.org/3.9/library/configparser.html

there are examples which use the 'with open ... as' variable for writing
a configuration file, but not for reading one.

Cheers,

Loris

-- 
This signature is currently under constuction.
-- 
https://mail.python.org/mailman/listinfo/python-list