Re: Detect naming typos (AttributeError) in function names

2023-11-06 Thread George Fischhof via Python-list
Dieter Maurer via Python-list  ezt írta (időpont:
2023. nov. 6., H, 19:13):

> c.bu...@posteo.jp wrote at 2023-11-6 12:47 +:
> >I would like to know how to detect (e.g. via a linter) typos in function
> >names imported from another module.
>
> One option is a test suite (--> Python's "unittest" package)
> with a sufficiently high coverage (near 100 %).
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Hi

PyCharm IDE warns you, also vulture
https://pypi.org/project/vulture/
finds dead code (not called / not used because of typo), and if you compile
the code:
https://docs.python.org/3/library/py_compile.html
it will generate syntax error if non-existent function is called.
linters can perhaps warn you (never had typos, because I use PyCharm)
need to check the linters' doc

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


String to Float, without introducing errors

2022-12-18 Thread Paul St George
So I am working on a physics paper with a colleague. We have a theory about 
Newtons Cradle. We answer the question why when you lift and drop balls 1 and 
2, balls 4 and 5 rise up. I could say more, but ... (if you are interested 
please write to me).

We want to illustrate the paper with animations. The theory includes distortion 
of the balls and this distortion is very very small. So, I am sent data with 
locations and dimensions to 13 decimal places. Something strange is happening 
with the animations: the balls are not moving smoothly. I do not know (yet) 
where the problem lies so it is difficult to provide a clear narrative.

Because there is a problem, I am investigating in all areas. This brings me to 
the question I asked here. I am not expecting six decimal places or three 
decimal places to be as accurate as thirteen decimal places, but I would like 
to be in control of or fully aware of what goes on under the bonnet.







 
>> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote:
On 12/17/2022 3:45 PM, Paul St George wrote:
> Thanks to all!
> It was the rounding rounding error that I needed to avoid (as Peter J. Holzer 
> suggested). The use of decimal solved it and just in time. I was about to 
> truncate the number, get each of the characters from the string mantissa, and 
> then do something like this:
> 
> 64550.727
> 
> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001)
> 
> Now I do not need to!

And that approach would not have helped you, because each of those 
calculations would be done as floating point, and you wouldn't have 
gotten any more precision (and maybe less) than simply doing 
float('64550.727').

Here is a small but interesting discussion thread about float vs Decimal:

https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string

Would you mind telling us why that degree of precision (that is, decimal 
vs float) matters for your problem?


>> On 17 Dec 2022, at 13:11, Alan Gauld > <https://mail.python.org/mailman/listinfo/python-list>> wrote:
>>
>> On 17/12/2022 11:51, Paul St George wrote:
>>> I have a large/long array of numbers in an external file. The numbers look 
>>> like this:
>>>
>>> -64550.727
>>> -64511.489
>>> -64393.637
>>> -64196.763
>>> -63920.2
>>
>>> When I bring the numbers into my code, they are Strings. To use the
>>> numbers in my code, I want to change the Strings to Float type
>>> because the code will not work with Strings but I do not want
>>> to change the numbers in any other way.
>>
>> That may be impossible. Float type is not exact and the conversion
>> will be the closest binary representation of your decimal number.
>> It will be very close but it may be slightly different when you
>> print it, for example. (You can usually deal with that by using
>> string formatting features.)
>>
>> Another option is to use the decimal numeric type. That has other
>> compromises associated with it but, if retaining absolute decimal
>> accuracy is your primary goal, it might suit you better.
>>
>>
>> -- 
>> 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


String to Float, without introducing errors

2022-12-18 Thread Paul St George
So I am working on a physics paper with a colleague. We have a theory about 
Newtons Cradle. We answer the question why when you lift and drop balls 1 and 
2, balls 4 and 5 rise up. I could say more, but ... (if you are interested 
please write to me).

We want to illustrate the paper with animations. The theory includes distortion 
of the balls and this distortion is very very small. So, I am sent data with 
locations and dimensions to 13 decimal places. Something strange is happening 
with the animations: the balls are not moving smoothly. I do not know (yet) 
where the problem lies so it is difficult to provide a clear narrative.

Because there is a problem, I am investigating in all areas. This brings me to 
the question I asked here. I am not expecting six decimal places or three 
decimal places to be as accurate as thirteen decimal places, but I would like 
to be in control of or fully aware of what goes on under the bonnet.

Here is a picture:
https://paulstgeorge.com/newton/cyclography.html
Thanks,
Paul



 
>> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote:
On 12/17/2022 3:45 PM, Paul St George wrote:
> Thanks to all!
> It was the rounding rounding error that I needed to avoid (as Peter J. Holzer 
> suggested). The use of decimal solved it and just in time. I was about to 
> truncate the number, get each of the characters from the string mantissa, and 
> then do something like this:
> 
> 64550.727
> 
> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001)
> 
> Now I do not need to!

And that approach would not have helped you, because each of those 
calculations would be done as floating point, and you wouldn't have 
gotten any more precision (and maybe less) than simply doing 
float('64550.727').

Here is a small but interesting discussion thread about float vs Decimal:

https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string

Would you mind telling us why that degree of precision (that is, decimal 
vs float) matters for your problem?


>> On 17 Dec 2022, at 13:11, Alan Gauld > <https://mail.python.org/mailman/listinfo/python-list>> wrote:
>>
>> On 17/12/2022 11:51, Paul St George wrote:
>>> I have a large/long array of numbers in an external file. The numbers look 
>>> like this:
>>>
>>> -64550.727
>>> -64511.489
>>> -64393.637
>>> -64196.763
>>> -63920.2
>>
>>> When I bring the numbers into my code, they are Strings. To use the
>>> numbers in my code, I want to change the Strings to Float type
>>> because the code will not work with Strings but I do not want
>>> to change the numbers in any other way.
>>
>> That may be impossible. Float type is not exact and the conversion
>> will be the closest binary representation of your decimal number.
>> It will be very close but it may be slightly different when you
>> print it, for example. (You can usually deal with that by using
>> string formatting features.)
>>
>> Another option is to use the decimal numeric type. That has other
>> compromises associated with it but, if retaining absolute decimal
>> accuracy is your primary goal, it might suit you better.
>>
>>
>> -- 
>> 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: String to Float, without introducing errors

2022-12-17 Thread Paul St George
Thanks to all!
It was the rounding rounding error that I needed to avoid (as Peter J. Holzer 
suggested). The use of decimal solved it and just in time. I was about to 
truncate the number, get each of the characters from the string mantissa, and 
then do something like this:

64550.727

64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001)

Now I do not need to!





> On 17 Dec 2022, at 13:11, Alan Gauld  wrote:
> 
> On 17/12/2022 11:51, Paul St George wrote:
>> I have a large/long array of numbers in an external file. The numbers look 
>> like this:
>> 
>> -64550.727
>> -64511.489
>> -64393.637
>> -64196.763
>> -63920.2
> 
>> When I bring the numbers into my code, they are Strings. To use the 
>> numbers in my code, I want to change the Strings to Float type 
>> because the code will not work with Strings but I do not want 
>> to change the numbers in any other way.
> 
> That may be impossible. Float type is not exact and the conversion
> will be the closest binary representation of your decimal number.
> It will be very close but it may be slightly different when you
> print it, for example. (You can usually deal with that by using
> string formatting features.)
> 
> Another option is to use the decimal numeric type. That has other
> compromises associated with it but, if retaining absolute decimal
> accuracy is your primary goal, it might suit you better.
> 
> 
> -- 
> 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


String to Float, without introducing errors

2022-12-17 Thread Paul St George
I have a large/long array of numbers in an external file. The numbers look like 
this:

-64550.727
-64511.489
-64393.637
-64196.763
-63920.2
-63563.037
-63124.156
-62602.254
-61995.895
-61303.548
-60523.651
-59654.66
...

When I bring the numbers into my code, they are Strings. To use the numbers in 
my code, I want to change the Strings to Float type because the code will not 
work with Strings but I do not want to change the numbers in any other way.

So, I want my Strings (above) to be these numbers.

-64550.727
-64511.489
-64393.637
-64196.763
-63920.2
-63563.037
-63124.156
-62602.254
-61995.895
-61303.548
-60523.651
-59654.66
...

Please help!










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


Re: Download Python 3.10.6 for windows

2022-08-31 Thread George Rwaga
Thanks for the suggestions, Mrab and Eryk.

Because my R and RStudio are under program files, for consistency I
installed Python in C:\program files\Python\Python310. I updated to the
latest version of Spyder in C:\program files\Spyder\Spyder5.3.3. As with R
and RStudio, some Python and Spyder files were automatically installed in
C:\Users\George.Rwaga\AppData\Local. I am not sure why the default for
installing Python
is C:\Users\x.x\AppData\local\programs\Python\Python310.

Initial tests suggest Spyder 5.3.3 is working fine. The real test will
probably come when I try to run some of my old code based on such sources
as Python for Finance by Yves Hilpisch, a book by the same title by Yuxing
Yan, Python for Data Analysis by Wes McKinney, etc.

Again, thanks.

George
--


On Tue, Aug 30, 2022 at 4:06 PM Eryk Sun  wrote:

> On 8/30/22, George Rwaga  wrote:
> >
> > 1. I installed Python 3.10.6 in the default directory
> > C:\Users\x.x\AppData\local\programs\Python\Python310
> > After the installation, there was no shortcut on my desktop.
>
> Shortcuts are created in the start menu. The installer doesn't modify
> the user's desktop or the desktop of all users, which many users don't
> want and would find annoying. Just copy the shortcuts from the start
> menu to the desktop if that's what you want. Right-click the icon in
> the start menu and choose to open the location. You can copy shortcuts
> from the opened Explorer window.
>
> > 2. I then decided to install Python3.10.6 in a customized directory
> > C:\program files\Python\Python310
> > I am being asked to verify access to this directly. I went to properties,
> > made what I thought were the relevant changes. But I keep getting asked
> to
> > verify access.
>
> Installing to "Program Files" requires elevating to get administrator
> access. All users have the right to read and execute files in a
> directory created in "Program Files", but adding, removing, or
> deleting files and directories requires administrator access, as it
> should.
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Download Python 3.10.6 for windows

2022-08-30 Thread George Rwaga
I last installed an updated version of python more than  a year back. I am
trying to download (from  https://www.python.org/downloads/ ) and install
Python 3.10.6 for Windows - but I keep running into problems.

1. I installed Python 3.10.6 in the default directory
C:\Users\x.x\AppData\local\programs\Python\Python310
After the installation, there was no shortcut on my desktop. I thought I
would just go to Python310 and create a shortcut. But I am unable to find
AppData.
2. I then decided to install Python3.10.6 in a customized directory
C:\program files\Python\Python310
I am being asked to verify access to this directly. I went to properties,
made what I thought were the relevant changes. But I keep getting asked to
verify access.

My R and RStudio are installed in C:\program files.

How should I proceed?

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


Re: exec() an locals() puzzle

2022-07-21 Thread george trojan
Thanks. That cdef-locals concept is consistent with the following example:

def f():
i = 1
def g(): print('i' in globals(), 'i' in locals())
def h(): print('i' in globals(), 'i' in locals()); i
g()
h()
f()

False False
False True

It is a mystery, which may be why the documentation for globals() and
locals() is 2-line long.


Le mer. 20 juill. 2022, à 19 h 31, Martin Di Paola <
martinp.dipa...@gmail.com> a écrit :

> I did a few tests
>
> # test 1
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  u = a
>  print(u)
> f()
>
> {'i': 1}
> 1
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 1, 'a': 1}
> 1
>
> # test 2
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  y = a
>  print(y)
> f()
> {'i': 1}
> 1
> {'i': 1, 'y': 1}
> {'i': 1}
> Traceback (most recent call last):
> NameError: name 'y' is not defined
>
>
> So test 1 and 2 are the same except that the variable 'y' is not
> present/present in the f's code.
>
> When it is not present, exec() modifies the f's locals and adds an 'y'
> to it but when the variable 'y' is present in the code (even if not
> present in the locals()), exec() does not add any 'y' (and the next
> eval() then fails)
>
> The interesting part is that if the 'y' variable is in the f's code
> *and* it is defined in the f's locals, no error occur but once again the
> exec() does not modify f's locals:
>
> # test 3
> def f():
>  i = 1
>  y = 42
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  y = a
>  print(y)
> f()
> {'i': 1, 'y': 42}
> 1
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 42}
> {'i': 1, 'y': 42, 'a': 42}
> 42
>
> Why does this happen? No idea.
>
> I may be related with this:
>
> # test 4
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  print(y)
> f()
> Traceback (most recent call last):
> NameError: name 'y' is not defined
>
> Despite exec() adds the 'y' variable to f's locals, the variable is not
> accessible/visible from f's code.
>
> So, a few observations (by no means this is how the vm works):
>
> 1) each function has a set of variables defined by the code (let's call
> this "code-defined locals" or "cdef-locals").
> 2) each function also has a set of "runtime locals" accessible from
> locals().
> 3) exec() can add variables to locals() (runtime) set but it cannot add
> any to cdef-locals.
> 4) locals() may be a superset of cdef-locals (but entries in cdef-locals
> which value is still undefined are not shown in locals())
> 5) due rule 4, exec() cannot add a variable to locals() if it is already
>   present in the in cdef-locals.
> 6) when eval() runs, it uses locals() set for lookup
>
> Perhaps rule 5 is to prevent exec() to modify any arbitrary variable of
> the caller...
>
> Anyways, nice food for our brains.
>
> On Wed, Jul 20, 2022 at 04:56:02PM +, george trojan wrote:
> >I wish I could understand the following behaviour:
> >
> >1. This works as I expect it to work:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >exec('y *= 2')
> >print('ok:', eval('y'))
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1, 'y': 1}
> >ok: 2
> >
> >2. I can access the value of y with eval() too:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >u = eval('y')
> >print(u)
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1, 'y': 1}
> >1
> >
> >3. When I change variable name u -> y, somehow locals() in the body of
> >the function loses an entry:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >y = eval('y')
> >print(y)
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1}
> >
>
> >---NameError
> >Traceback (most recent call last)
> >Input In [1], in ()  7 print(y)  8 # y
> >= eval('y')  9 #print('ok:', eval('y'))---> 10 f()
> >
> >Input In [1], in f()  4 exec('y = i; print(y); print(locals())')
> >   5 print(locals())> 6 y = eval('y')  7 print(y)
> >
> >File :1, in 
> >NameError: name 'y' is not defined1.
> >
> >Another thing: within the first exec(), the print order seems
> >reversed. What is going on?
> >
> >BTW, I am using python 3.8.13.
> >
> >George
> >--
> >https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


exec() an locals() puzzle

2022-07-20 Thread george trojan
I wish I could understand the following behaviour:

1. This works as I expect it to work:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
exec('y *= 2')
print('ok:', eval('y'))
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
ok: 2

2. I can access the value of y with eval() too:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
u = eval('y')
print(u)
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
1

3. When I change variable name u -> y, somehow locals() in the body of
the function loses an entry:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
y = eval('y')
print(y)
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1}

---NameError
Traceback (most recent call last)
Input In [1], in ()  7 print(y)  8 # y
= eval('y')  9 #print('ok:', eval('y'))---> 10 f()

Input In [1], in f()  4 exec('y = i; print(y); print(locals())')
   5 print(locals())> 6 y = eval('y')  7 print(y)

File :1, in 
NameError: name 'y' is not defined1.

Another thing: within the first exec(), the print order seems
reversed. What is going on?

BTW, I am using python 3.8.13.

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


Re: Popular Python Package 'ctx' Hijacked to Steal AWS Keys

2022-05-25 Thread George Fischhof
Turritopsis Dohrnii Teo En Ming  ezt írta (időpont:
2022. máj. 25., Sze, 15:49):

> Subject: Popular Python Package 'ctx' Hijacked to Steal AWS Keys
>
> Good day from Singapore,
>
> Sharing this article for more awareness.
>
> Article: Popular PyPI Package 'ctx' and PHP Library 'phpass' Hijacked
> to Steal AWS Keys
> Link:
> https://thehackernews.com/2022/05/pypi-package-ctx-and-php-library-phpass.html
>
> Thank you.
>
> Regards,
>
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
> 25 May 2022 Wed
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi All,

it's got to my mind that PYPA, community, and developers should develop
some mechanism to protect against similar threats.

For example security checkers could be added to the upload flow, before a
package appears, and becomes downloadable.
Compiled parts should be allowed only in source, and security checkers
would check those too, and compile from source and publish package only
after these checks executed and did not found any harmful thing.


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Testing an app protected by Okta authorization code with PKCE flow

2022-04-29 Thread George Fischhof
Hi Folks,

has anyone of you a working solution for testing an app protected by Okta
authorization code with PKCE flow?
Meaning to get a bearer token?

I saw / read several articles about it on the net, and several hacks (that
is not problem now ;) ), but it seems that neither of them works with Okta.

We are using Okta's .net backend stuff and Angular widget

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for convenience

2022-03-24 Thread Paul St George
On 22/03/2022 18.04, dn wrote:

> and thank you - it is refreshing, if not enervating, to receive feedback
> on efforts-expended!
> 
> You will also notice, that now you understand the id() stuff, the
> tag-team effect between @Chris and I (which we have often played, albeit
> not by-design), now makes sense as an whole (if you didn't quite follow,
> earlier).
> 
> 
> My research-topic is Cognitive Psychology (how we learn - albeit not
> usually in Python). I found this conversation useful, and may well apply
> it as an example (with your permission, and suitably anonymised) - one
> doesn't need to be a 'computer person' to follow the logic and thus
> realise the dissonance!
> 
> While learning (this part of) Python and adding to 'previous
> experience', you formed a "mental-model" of how things work (just as we
> all do). However, when it came time to implement this knowledge:
> 
> - you created a 'situation'
> - (all) things didn't 'work' (which also required realisation)
> - you analysed and rationalised (but noted inconsistency)
> - you asked a question (which many of us quickly understood)
> - you've learned/corrected
> 
> 
> The 'issue' is *not* a fault on your part, nor (necessarily) a lack of
> learning or a lack of effort. So, no criticism from me!
> 
> The (under-lying) lesson, is that we (as trainers, but with application
> to all helpers, pair-programmers, mentors, documentation-writers, et al
> - working with less-experienced colleagues) shouldn't spout a whole load
> of 'facts', 'rules', and formulae/s - which we expect to be committed to
> memory. We need to help form a 'correct' mental-model ("correct" being
> defined by the Python interpreter and 'the Python gods' who build it -
> big "thank you" to them!).
> 
> Accordingly, my criticism of tests/exams which require recitation of
> facts ("parroting"), compared with "mastery" (can you actually DO what
> is being asked). More importantly, and finally getting to the point:
> 'tests' should be defined to reveal these (personal) 'quirks' of
> learning/understanding, which led to a 'faulty' mental-model!
> 
> Your rationale made sense, was logical and understandable. How are you
> to know that Python deems it 'wrong'? (until a 'test' shows you!)
> 
> The 'interest' should not be on the people who, and all the 'answers'
> which, were 'correct'. What is more informative, is why someone (aside
> from guessing, ie intelligent, reasonable, after learning the material,
> exerting effort...) got it 'wrong' - but thought his/her path was true!
> -- 
> Regards,
> =dn


Wow, this is super interesting. You have my permission, and please feel free to 
contact me offline if you want to ask anything.

Yes, I had noticed the tandem with @Chris. I think I needed both! I already 
have a folder on my Mac called ‘Cameron’. Perhaps I now need an additional 
folder. Then I can ask my question about whether Python grows to be more like 
its programmers, or do programmers learn to think Pythonically?


—
Paul St George

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


Re: for convenience

2022-03-22 Thread Paul St George
On 21/03/2022 17.47, Avi Gross wrote:

> So, I ask Paul what other language than python he has used before, just out 
> of curiosity.

The other language I have used (and often) is Processing. Before that, and a 
long time ago, Lingo. 

—
Paul






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


Re: for convenience

2022-03-22 Thread Paul St George
On 21/03/2022 18.02, Cameron Simpson wrote:

> On 21Mar2022 22:12, Paul St George  wrote:
> >When I am writing code, I often do things like this:
> >
> >context = bpy.context  # convenience
> >
> >then whenever I need bpy.context, I only need to write context
> >
> >
> >Here’s my question:
> >
> >When I forget to use the convenient shorter form
> >
> >why is bpy.context not interpreted as bpy.bpy.context?
> 
> Because it still has its original meaning. You haven't changed the 
> meaning of the word "context" in any position, you have simply made a 
> module level name "context" referring to the same object to which 
> "bpy.context" refers.
> 
> So your module global namespace contains, initially, "bpy". Then you 
> assign:
> 
> context = bpy.context
> 
> and now your module global namespace contains "bpy" and "context". But 
> "bpy.context" is still what it was, because "bpy" is an object and you 
> have done nothing to its ".context" attribute.
> 
> Consider this code:
> 
> class O:
> pass
> 
> o = O()
> o.x = 3
> 
> x = o.x
> 
> print(x)
> print(o.x)
> 
> I expect to see "3" twice. What do you expect?
> 
> "bpy" is no different to "o" - it's just a name.


Thanks Cameron,
What did I expect? Well, I expected to see  "3” twice, but I did not understand 
why. Now I do!

—
Thanks,
Paul








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


Re: for convenience

2022-03-22 Thread Paul St George
On 21/03/2022 18.04, dn wrote:

> On 22/03/2022 10.17, Chris Angelico wrote:
> > On Tue, 22 Mar 2022 at 08:13, Paul St George  > <https://mail.python.org/mailman/listinfo/python-list>> wrote:
> >>
> >>
> >> When I am writing code, I often do things like this:
> >>
> >> context = bpy.context  # convenience
> >>
> >> then whenever I need bpy.context, I only need to write context
> >>
> >>
> >> Here’s my question:
> >>
> >> When I forget to use the convenient shorter form
> >>
> >> why is bpy.context not interpreted as bpy.bpy.context?
> >>
> > 
> > I don't understand the question. When you do that "for convenience"
> > assignment, what you're doing is creating a local variable named
> > "context" which refers to the same thing that bpy.context does (or did
> > at the time of the assignment, but presumably you only do this when
> > bpy.context won't get reassigned). It has no effect on any other name.
> > There's no magic happening here - it's just assignment to the name
> > context, like anything else.
> > 
> > What are you expecting to happen here?
> 
> 
> It's the way Python works.
> 
> try:
> 
> context = bpy.context  # convenience
> print( id(context), id(bpy.context) )
> 
> Remember that the 'relationship' between the two is established at
> run-time and at the data/address 'level' - and not at compile-time. Thus
> "context" points to a memory location, and does not 'stand for'
> "bpy.context" anywhere other than in your mind.
> 
> (which is why we often need to use a copy() when we want 'separate data'
> - see also the 'counters' Python uses to manage "garbage collection")
> 
> -- 
> Regards,
> =dn


Thanks dn,
I did exactly as you suggested.

import bpy

context = bpy.context  # convenience variable
print( id(context), id(bpy.context) )

4932508928 4932508928

The two are the same, and that makes it crystal clear. And, as a bonus you have 
explained a use of copy().

—
Thanks,
Paul




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


Re: for convenience

2022-03-21 Thread Paul St George
Hi,
I do not (knowingly) have a module called ‘context'.




> On 21 Mar 2022, at 22:24, Paul Bryan  wrote:
> 
> Assuming `bpy` is a module, you're creating a new attribute in your module, 
> `context`, that contains a reference to the same object that is referenced in 
> the `context` attribute in the `bpy` module.
> 
> On Mon, 2022-03-21 at 22:12 +0100, Paul St George wrote:
>> 
>> When I am writing code, I often do things like this:
>> 
>> context = bpy.context  # convenience
>> 
>> then whenever I need bpy.context, I only need to write context
>> 
>> 
>> Here’s my question:
>> 
>> When I forget to use the convenient shorter form 
>> 
>> why is bpy.context not interpreted as bpy.bpy.context?
>> 
>> 
>> —
>> Paul St George
>> 
>> 
>> 
>> 
>> 
> 

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


for convenience

2022-03-21 Thread Paul St George

When I am writing code, I often do things like this:

context = bpy.context  # convenience

then whenever I need bpy.context, I only need to write context


Here’s my question:

When I forget to use the convenient shorter form 

why is bpy.context not interpreted as bpy.bpy.context?


—
Paul St George





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


[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread George Gensure


New submission from George Gensure :

Instantiating an exception and raising it multiple times causes 1 frame and 2 
traceback objects to remain allocated for each raise. The attached example 
causes python to consume 8GB of ram after a few seconds of execution on 
Windows/Linux.

--
components: Interpreter Core
files: exc.py
messages: 413035
nosy: ggensure
priority: normal
severity: normal
status: open
title: Raising exception multiple times leaks memory
type: resource usage
versions: Python 3.11
Added file: https://bugs.python.org/file50619/exc.py

___
Python tracker 
<https://bugs.python.org/issue46717>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45904] Pasting the U00FF character into Python REPL misinterprets character

2021-11-26 Thread George King


George King  added the comment:

Edit: `chr(0xff)`

--

___
Python tracker 
<https://bugs.python.org/issue45904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45904] Pasting the U00FF character into Python REPL misinterprets character

2021-11-26 Thread George King

New submission from George King :

Using macOS 11.6 Terminal.app with Python 3.10.0 installed directly from 
python.org.

I open the REPL. If I enter `char(0xff)` I get back 'ÿ' as expected (U00FF 
LATIN SMALL LETTER Y WITH DIAERESIS).

However, If I copy this character with surrounding quotes, and then paste it 
into the REPL, it pastes as '' and evaluates to the empty string.

If I copy it without quotes and then paste into the REPL, I see nothing. When I 
hit return, the prompt renders as `>>> ^M>>>`. This suggests that the character 
is getting misinterpreted as a control character or something.

If I paste it into the terminal shell when the Python REPL is not running, it 
appears as the latin1 letter that I expect.

If I run `python3 -c 'print("ÿ")'` the character prints fine.

It seems to me that the python REPL is setting some terminal mode that fails on 
this particular character. Perhaps this is a problem with the macOS 
readline/libedit implementation?

It seems that only U00FF is problematic; U00FE and U01000 both paste in just 
fine.

I verified that my terminal profile is set to UTF-8 encoding. I also repeated 
this experiment in the Kitty terminal emulator, and got identical results.


Here is the readline version:
>>> readline._READLINE_LIBRARY_VERSION
'EditLine wrapper'
>>> readline._READLINE_RUNTIME_VERSION
1026
>>> readline._READLINE_VERSION
1026

--
messages: 407065
nosy: gwk
priority: normal
severity: normal
status: open
title: Pasting the U00FF character into Python REPL misinterprets character
type: behavior
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue45904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45900] Type annotations needed for convenience functions in ipaddress module

2021-11-25 Thread William George


Change by William George :


--
keywords: +patch
pull_requests: +28015
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29778

___
Python tracker 
<https://bugs.python.org/issue45900>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45900] Type annotations needed for convenience functions in ipaddress module

2021-11-25 Thread William George


New submission from William George :

The convenience factory functions in the ipaddress module each return one of 
two types (IPv4Network vs IPv6Network, etc).  Modern code wants to be friendly 
to either stack, and these functions are great at enabling that, but current 
implementation blocks type inference for most (all?) IDEs.

Proposal is easy enough, specifying return type of e.g. `Union[IPv4Network, 
IPv6Network]` for these factory functions.  

I believe the rest of the public interface for this module is unambiguous 
enough that annotations aren't needed, but if others see value they could be 
added easily enough.

For some of these there exists a version-independent base class that could be 
referenced instead of a union, but it's not clear to me how well IDEs will 
actually honor such an annotation referencing an internal class 
(single-underscore).  My limited testing of that didn't work well and there's 
no such base class for the Interface classes anyway. 

PR for this incomming.

--
components: Library (Lib)
messages: 407005
nosy: pmoody, wrgeorge1983
priority: normal
severity: normal
status: open
title: Type annotations needed for convenience functions in ipaddress module
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue45900>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43683] Handle generator (and coroutine) state in the bytecode.

2021-10-27 Thread Damien George


Damien George  added the comment:

Thanks for confirming the bug.

Sending non-None to a not-started generator could arguably be case (2), because 
that's exactly the semantics introduced by the commit that broke the test case 
:)

Honestly I don't have a strong opinion on which way this goes.  But I think it 
would be interesting to know if there was code out there that relied on the 
original behaviour.

--

___
Python tracker 
<https://bugs.python.org/issue43683>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43683] Handle generator (and coroutine) state in the bytecode.

2021-10-20 Thread Damien George


Damien George  added the comment:

It looks like this change introduced a subtle, and maybe intended (?), 
behavioural change.

Consider (from MicroPython's test suite):

def f():
n = 0 
while True:
n = yield n + 1 
print(n)

g = f()
try:
g.send(1)
except TypeError:
print("caught")

print(g.send(None))
print(g.send(100))
print(g.send(200))

This used to work prior to commit b37181e69209746adc2119c471599a1ea5faa6c8.  
But after that commit it fails on the print(g.send(None)) because the generator 
is now stopped.

--
nosy: +dpgeorge

___
Python tracker 
<https://bugs.python.org/issue43683>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Making command-line args available to deeply-nested functions

2021-08-31 Thread George Fischhof
George Fischhof  ezt írta (időpont: 2021. aug. 29., V,
21:27):

>
>
> Loris Bennett  ezt írta (időpont: 2021. aug.
> 26., Cs, 16:02):
>
>> George Fischhof  writes:
>>
>> [snip (79 lines)]
>>
>> >> > Hi,
>> >> >
>> >> > Also you can give a try to click and / or  typer packages.
>> >> > Putting args into environment variables can be a solution too
>> >> > All of these depends on several things: personal preferences,
>> colleagues
>> >> /
>> >> > firm standards, the program, readability, variable accessibility (IDE
>> >> > support, auto completition) (env vars not supported by IDEs as they
>> are
>> >> not
>> >> > part of code)
>> >>
>> >> Thanks for the pointers, although I have only just got my head around
>> >> argparse/configargparse, so click is something I might have a look at
>> >> for future project.
>> >>
>> >> However, the question of how to parse the arguments is somewhat
>> separate
>> >> from that of how to pass (or not pass) the arguments around within a
>> >> program.
>>
>> [snip (16 lines)]
>> >
>> > Hi,
>> > I thought not just parsing, but the usage method: you add a decorator to
>> > the function where you want to use the parameters. This way you do not
>> have
>> > to pass the value through the calling hierarchy.
>> >
>> > Note: typer is a newer package, it contains click and leverages command
>> > line parsing even more.
>>
>> Do you have an example of how this is done?  From a cursory reading of
>> the documentation, it didn't seem obvious to me how to do this, but then
>> I don't have much understanding of how decorators work.
>>
>> Cheers,
>>
>> Loris
>>
>>
>> --
>> This signature is currently under construction.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> Hi,
>
> will create a sample code on Monday - Tuesday
>
> BR,
> George
>


Hi,

here is the program ;-) (see below)
typer does not uses decorators, to solve this problem they advice to use
click's decorators, mixing typer and click.
Practically I prefer not to mix them, also the parts for easiest way to do
this just available in latest click, which is not supported in typer.

So I created all the stuff in click, 8.x should be used

BR,
George


import click


# read command line parameters
@click.command()
@click.option('--level_1', help='Level 1')
@click.option('--level_2', help='Level 2')
def main(level_1, level_2):
# put command line parameters into global context
ctx = click.get_current_context()
ctx.meta['level_1'] = level_1
ctx.meta['level_2'] = level_2

level_1_function()


# pass / inject level_1 parameter to this function
@click.decorators.pass_meta_key('level_1')
def level_1_function(level_1):
print(f'level 1 variable: {level_1}')
level_2_function()


# pass / inject level_2 parameter to this function
@click.decorators.pass_meta_key('level_2')
def level_2_function(level_2):
print(f'level 2 variable: {level_2}')


if __name__ == "__main__":
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-29 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
26., Cs, 16:02):

> George Fischhof  writes:
>
> [snip (79 lines)]
>
> >> > Hi,
> >> >
> >> > Also you can give a try to click and / or  typer packages.
> >> > Putting args into environment variables can be a solution too
> >> > All of these depends on several things: personal preferences,
> colleagues
> >> /
> >> > firm standards, the program, readability, variable accessibility (IDE
> >> > support, auto completition) (env vars not supported by IDEs as they
> are
> >> not
> >> > part of code)
> >>
> >> Thanks for the pointers, although I have only just got my head around
> >> argparse/configargparse, so click is something I might have a look at
> >> for future project.
> >>
> >> However, the question of how to parse the arguments is somewhat separate
> >> from that of how to pass (or not pass) the arguments around within a
> >> program.
>
> [snip (16 lines)]
> >
> > Hi,
> > I thought not just parsing, but the usage method: you add a decorator to
> > the function where you want to use the parameters. This way you do not
> have
> > to pass the value through the calling hierarchy.
> >
> > Note: typer is a newer package, it contains click and leverages command
> > line parsing even more.
>
> Do you have an example of how this is done?  From a cursory reading of
> the documentation, it didn't seem obvious to me how to do this, but then
> I don't have much understanding of how decorators work.
>
> Cheers,
>
> Loris
>
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi,

will create a sample code on Monday - Tuesday

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-23 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
23., H 19:26):

> George Fischhof  writes:
>
> > Loris Bennett  ezt írta (időpont: 2021. aug.
> > 20., P 17:54):
> >
> >> Julio Di Egidio  writes:
> >>
> >> > On Friday, 20 August 2021 at 11:54:00 UTC+2, Loris Bennett wrote:
> >> >> Hi,
> >> >>
> >> >> TL;DR:
> >> >>
> >> >> If I have a command-line argument for a program, what is the best way
> >> >> of making this available to a deeply-nested[1] function call without
> >> >> passing the parameter through every intermediate function?
> >> >
> >> > To not pass arguments you need shared state ("global variables"): and
> >> > options in shard state, unless you have very good reasons to do
> >> > otherwise, is simply a no no.
> >>
> >> Doesn't that slightly depend on the size of your "globe"?  If a program
> >> does a few, in some sense unrelated things, and, say, only runs for a
> >> few minutes, could you not decide to make a particular parameter global,
> >> even though only one function needs it?  In general, however, I would
> >> also avoid this.
> >>
> >> > 
> >> >> I can see that the top-level could just create an object from a class
> >> >> which encapsulates everything, but what if I want to keep the
> salutation
> >> >> generation separate, so that I can have a separate program which just
> >> >> generates the salutation and print it to the terminal?
> >> >
> >> > Yes, that's basically the way to go: parse arguments into a structure
> (an
> >> > object) that contains all options/parameters then pass that down.
> Next
> >> level:
> >> > some sections of your code may require a certain subset of those
> >> options, some
> >> > may require some other, so you would structure your options object in
> >> > sub-objects for the various sets of correlated options, then rather
> pass
> >> just
> >> > the sub-object(s) that are relevant to the section of code you are
> >> calling.
> >> > Variations are of course possible, anyway that's the basic idea.
> >> >
> >> > Also have a look at the "argparse" library, it does all the heavy
> >> lifting for
> >> > the parsing and creation of those objects, definitely advised for in
> non
> >> trivial
> >> > cases: <https://docs.python.org/3/library/argparse.html>.
> >>
> >> I am already using 'argparse' ('configargparse' actually).  What aspect
> >> should I be looking at in order to produce "sub-objects"?
> >>
> >> >> I guess I am really asking how to avoid "passing through" arguments
> to
> >> >> functions which only need them to call other functions, so maybe the
> >> >> answer is just to avoid nesting.
> >> >
> >> > No, you don't get rid of code structure just not to pass arguments to
> >> > a function...  Code may be poorly structured, but that's another
> >> > story.
> >>
> >> As I am writing new code it is more a question of imposing structure,
> >> rather than getting rid of structure.  Unwritten code for a given
> >> purpose obviously has some sort of structure with regards to, say, loops
> >> and conditions, but I am less sure about the implications for how the
> >> code should be nested.  Another argument against deeply-nested functions
> >> is the increased complexity of testing.
>
> [snip (15 lines)]>
>
> > Hi,
> >
> > Also you can give a try to click and / or  typer packages.
> > Putting args into environment variables can be a solution too
> > All of these depends on several things: personal preferences, colleagues
> /
> > firm standards, the program, readability, variable accessibility (IDE
> > support, auto completition) (env vars not supported by IDEs as they are
> not
> > part of code)
>
> Thanks for the pointers, although I have only just got my head around
> argparse/configargparse, so click is something I might have a look at
> for future project.
>
> However, the question of how to parse the arguments is somewhat separate
> from that of how to pass (or not pass) the arguments around within a
> program.
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

>
>
>



Hi,
I thought not just parsing, but the usage method: you add a decorator to
the function where you want to use the parameters. This way you do not have
to pass the value through the calling hierarchy.

Note: typer is a newer package, it contains click and leverages command
line parsing even more.


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-21 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
20., P 17:54):

> Julio Di Egidio  writes:
>
> > On Friday, 20 August 2021 at 11:54:00 UTC+2, Loris Bennett wrote:
> >> Hi,
> >>
> >> TL;DR:
> >>
> >> If I have a command-line argument for a program, what is the best way
> >> of making this available to a deeply-nested[1] function call without
> >> passing the parameter through every intermediate function?
> >
> > To not pass arguments you need shared state ("global variables"): and
> > options in shard state, unless you have very good reasons to do
> > otherwise, is simply a no no.
>
> Doesn't that slightly depend on the size of your "globe"?  If a program
> does a few, in some sense unrelated things, and, say, only runs for a
> few minutes, could you not decide to make a particular parameter global,
> even though only one function needs it?  In general, however, I would
> also avoid this.
>
> > 
> >> I can see that the top-level could just create an object from a class
> >> which encapsulates everything, but what if I want to keep the salutation
> >> generation separate, so that I can have a separate program which just
> >> generates the salutation and print it to the terminal?
> >
> > Yes, that's basically the way to go: parse arguments into a structure (an
> > object) that contains all options/parameters then pass that down.  Next
> level:
> > some sections of your code may require a certain subset of those
> options, some
> > may require some other, so you would structure your options object in
> > sub-objects for the various sets of correlated options, then rather pass
> just
> > the sub-object(s) that are relevant to the section of code you are
> calling.
> > Variations are of course possible, anyway that's the basic idea.
> >
> > Also have a look at the "argparse" library, it does all the heavy
> lifting for
> > the parsing and creation of those objects, definitely advised for in non
> trivial
> > cases: <https://docs.python.org/3/library/argparse.html>.
>
> I am already using 'argparse' ('configargparse' actually).  What aspect
> should I be looking at in order to produce "sub-objects"?
>
> >> I guess I am really asking how to avoid "passing through" arguments to
> >> functions which only need them to call other functions, so maybe the
> >> answer is just to avoid nesting.
> >
> > No, you don't get rid of code structure just not to pass arguments to
> > a function...  Code may be poorly structured, but that's another
> > story.
>
> As I am writing new code it is more a question of imposing structure,
> rather than getting rid of structure.  Unwritten code for a given
> purpose obviously has some sort of structure with regards to, say, loops
> and conditions, but I am less sure about the implications for how the
> code should be nested.  Another argument against deeply-nested functions
> is the increased complexity of testing.
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

>
>
>


Hi,

Also you can give a try to click and / or  typer packages.
Putting args into environment variables can be a solution too
All of these depends on several things: personal preferences, colleagues /
firm standards, the program, readability, variable accessibility (IDE
support, auto completition) (env vars not supported by IDEs as they are not
part of code)

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue44916] Undefined/random behaviour when importing two modules with the same name but different source files

2021-08-14 Thread George


New submission from George :

Warning: There's a higher probability this is "expected" undefined behaviour or 
not even undefined and I'm just a moron. In addtion, I couldn't actually 
replicate it outside of the specific context it happened. But if it sounds 
plausible and it's something that shouldn't happen I can spend more time trying 
to replicate.

1. In two different python processes I'm "dynamically" creating a module named 
`M` using a file `m1.py` that contains a class `C`. Then I create an object of 
tpye `C` and pickle it. (let's call this object `c1`)
2. In a different thread I do the exact same thing, but the file is `m2.py` 
then I create an object of type `C` and pickle it. (call this one `c2`)
3. Then, in the same thread, I recreate the module named `M` from `m1.py` and 
unpickle `c1`, second I create a module named `M` from `m2.py` (this doesn't 
cause an error) and unpickle `c2`.
4. This (spurprisingly?) seems to basically work fine in most cases. Except for 
one (and I can't find why it's special) where for some reason `c2` starts 
calling the methods from a class that's not it's own. In other words `c1` 
usually maps ot `M.C --> m1.py` and `c2` to `M.C --> m2.py` | But randomly `c2` 
will start looking up methods in `M.C --> m1.py`, or at least that's what stack 
traces & debuggers seem to indicate.

The way I create the module `M` in all cases:

```
with open(`m1.py`, 'wb') as fp:
fp.write(code.encode('utf-8'))
spec = importlib.util.spec_from_file_location('M', fp.name)
temp_module = importlib.util.module_from_spec(spec)
sys.modules['M] = temp_module
spec.loader.exec_module(temp_module)

# Note: Same for the other module but using `m2.py`, the code I use here 
contains a class `C` in both cases
```

This seems, unexpected. I wouldn't expect the recreation to cause a crash, but 
I'd expect it to either override the previous `M` for all existing objects 
instantiated from that module in all cases, or in no cases... currently it 
seems that both modules stay loaded and lookups are made randomly.

--
components: Interpreter Core
messages: 399596
nosy: George3d6
priority: normal
severity: normal
status: open
title: Undefined/random behaviour when importing two modules with the same name 
but different source files
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue44916>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44875] Update dis.findlinestarts documentaiton to reflect new usage of `co_lines` (PEP 626)

2021-08-09 Thread George King


George King  added the comment:

I should also mention that my reading was not exhaustive, so there may be other 
docs that need updating as well.

--

___
Python tracker 
<https://bugs.python.org/issue44875>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44875] Update dis.findlinestarts documentaiton to reflect new usage of `co_lines` (PEP 626)

2021-08-09 Thread George King


New submission from George King :

`dis.findlinestarts()` has been changed to use the no `co_lines()` function. 
(Blame indicates commit 877df851c3e by Mark Shannon.) However the docs 
currently state that it uses the older `co_firstlineno` and `co_lnotab`: 
https://docs.python.org/3.10/library/dis.html#dis.findlinestarts.

My cursory understanding of `dis.py` internals is that `get_instructions` 
relies on `findlinestarts`, implying that both of these APIs are going to 
return different line numbers than they did previously. I am perfectly fine 
with this, and hopeful that the PEP 626 changes will improve tool accuracy.

At minimum the `dis` docs should be updated. I also suggest that some kind of 
note about this be added to the PEP 626 text, because the way it reads now 
suggests that it avoids breakage by creating the new `co_lines` API. However it 
seems that users of the higher level dis APIs are going to see subtly different 
behavior.

FWIW I am fine with the change, and I hope this doesn't instigate a reversion 
to the old behavior. `lnotabs` semantics were very cryptic and seemed rather 
broken when I attempted to use it years ago. I am revisiting an experimental 
code coverage tool in part because of the PEP.

--
assignee: docs@python
components: Documentation
messages: 399290
nosy: Mark.Shannon, docs@python, gwk
priority: normal
severity: normal
status: open
title: Update dis.findlinestarts documentaiton to reflect new usage of 
`co_lines` (PEP 626)
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue44875>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44671] Create a built-in yaml module

2021-07-21 Thread Jurj Andrei George


Jurj Andrei George  added the comment:

I would also like to have yaml in the stdlib.

I reckon it would make sense to at least discuss yaml given that toml is on its 
way in the stdlib.

By the time a toml parser gets added, yaml will be the only major data 
serialization language to not be included in the stdlib.

--
nosy: +TheOneTheOnlyJJ

___
Python tracker 
<https://bugs.python.org/issue44671>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Definition of "property"

2021-06-02 Thread George Fischhof
Greg Ewing  ezt írta (időpont: 2021. jún. 2.,
Sze, 4:01):

> On 1/06/21 7:01 am, Alan Gauld wrote:
> > That was the point, the OP said it was a book about OOP.
> > Not a book about "OOP in Python".
>
> In that case it would be best to avoid the word, or give
> a definition of the way he's using it, making it clear
> that it's not a universal definition. Python's definition
> is somewhat unusual, and so would not be appropriate.
>
> --
> Greg
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Hi,

I think in OOP point of view one can write that property is the python
implementation of the OOP concepts:
Encapsulation and Information hiding

Some explanation for beginners on these paradigms:
https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36384] [security] CVE-2021-29921: ipaddress Should not reject IPv4 addresses with leading zeroes as ambiguously octal

2021-05-25 Thread George-Cristian Bîrzan

George-Cristian Bîrzan  added the comment:

I think the only thing I'd improve would be to mention that this issue is the 
one that introduced the bug, otherwise it looks a bit weird.

--

___
Python tracker 
<https://bugs.python.org/issue36384>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36384] [security] CVE-2021-29921: ipaddress Should not reject IPv4 addresses with leading zeroes as ambiguously octal

2021-05-25 Thread George-Cristian Bîrzan

George-Cristian Bîrzan  added the comment:

The timeline there is wrong. This issue's creation time isn't the disclosure 
time, it's when the bug was introduced. The disclosure was on 30th of May, when 
I emailed secur...@python.org and Christian Heimes commented here and made 
https://github.com/python/cpython/pull/25099. Even though Serhiy Storchaka 
commented that this could be a security issue back when the issue was new, the 
date would be 30th of March 2019, not 20th.

--

___
Python tracker 
<https://bugs.python.org/issue36384>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36384] ipaddress Should not reject IPv4 addresses with leading zeroes as ambiguously octal

2021-03-31 Thread George-Cristian Bîrzan

Change by George-Cristian Bîrzan :


--
nosy: +gc2

___
Python tracker 
<https://bugs.python.org/issue36384>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43523] Handling Ctrl+C when waiting on stdin on Windows via winrs

2021-03-16 Thread George Sovetov


New submission from George Sovetov :

Ctrl+C alone has no effect, but Ctrl+Break works:
```
winrs -r:127.0.0.1:20465 -u:Administrator -p:qweasd123 python -c "import 
sys;sys.stdin.read(1)"
```
Although, if I press Ctrl+C, type zero or more symbols and then press Enter, 
KeyboardInterrupt is raised:
```
lalala
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 22, in decode
def decode(self, input, final=False):
KeyboardInterrupt
^C^C
```

With the following commands, both Ctrl+C and Ctrl+Break work:
```
winrs -r:127.0.0.1:20465 -u:Administrator -p:qweasd123 python -c "import 
time;time.sleep(10)"
"c:\Program Files\Python39\python.exe" -c "import sys; sys.stdin.read(1)"
"c:\Program Files\Python39\python.exe" -c "import time;time.sleep(10)"
```

I faced this issue when working with WSMV (Windows remoting API) directly, but 
I reproduced this with winrs to make sure it's not a bug in my code. I send the 
Ctrl+C signal, got a no-error response, then poll the running command. It 
behaves as if a signal had no effect.

--
messages: 388890
nosy: sovetov
priority: normal
severity: normal
status: open
title: Handling Ctrl+C when waiting on stdin on Windows via winrs
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue43523>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43161] Taking sum of massive list comprehension results in total system crash.

2021-02-07 Thread George


George  added the comment:

Thanks Christian for the solutions. I am guessing that since it is my entire 
machine that crashes, and python is not simply killed for requesting so much 
memory, that this is an operating system problem. Should I submit this as a bug 
to the kernel project then?

George

--

___
Python tracker 
<https://bugs.python.org/issue43161>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43161] Taking sum of massive list comprehension results in total system crash.

2021-02-07 Thread George


New submission from George :

I tried running the following command in the interpreter, and without fail it 
will completely crash my entire computer.

Python 3.8.7 (default, Jan 20 2021, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> sum([i for i in range(10**8 + 10**9)])

My kernel is 5.10.12-100

I am running on Fedora 32 with Cinnamon Desktop if it helps. Let me know if you 
need any other information. 

I eagerly await resolution of this bug, as I want to know the result of the 
computation. Unless, of course it is harebrained, then we should ignore because 
Guido already discussed such computations.

George

--
messages: 386615
nosy: U9dB37BPZx
priority: normal
severity: normal
status: open
title: Taking sum of massive list comprehension results in total system crash.
type: crash
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue43161>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: [Python-authors] Query

2021-01-11 Thread George Fischhof
Eduardo Emén Muñoz  ezt írta (időpont: 2021. jan. 8.,
P, 17:23):

> Dear Srs,
>
>  I apologize if this is not the right place to ask this question, I am
> Biologist teaching Python language (in spanish)  focused in Molecular
> Biology.
>
>  People interested often ask me if my classes/course has a valid
> certification and I have to say no, so my question is :
>
> What can I do for provide a valid diploma with the Python logo to my
> students? I mean, how I would be allowed to give a valid
> Python logo on my students diploma? I have tried to contact local
> institutions like Biology's college, Education Ministry , etc but no
> success at all.
>
> Many thanks for your time reading this email, sorry for my poor english
> and thanks in advance.
>
>
> ___
> Python-authors mailing list
> python-auth...@python.org
> https://mail.python.org/mailman/listinfo/python-authors


Hi,

the good forum for similar questions is  python-list@python.org mail list -
I think ;-)

Right _now_ Microsoft created a Python exam, I do not know how much is that
appreciated, or accepted, but there is.
As I know this is the only one somewhat standardised exam now.
Of course there are several institutes holding Python course and exam

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue42409] Interpreter exit blocks waiting for ThreadPoolExecutor.map

2020-11-19 Thread George Stefos


Change by George Stefos :


--
nosy: +stefosgiwrgos

___
Python tracker 
<https://bugs.python.org/issue42409>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42409] Interpreter exit blocks waiting for ThreadPoolExecutor.map

2020-11-19 Thread George Sakkis


New submission from George Sakkis :

ThreadPoolExecutor.map() prevents interpreter exit if there is a reference to 
the generator it returns. In the attached script:

- `python threadpool_map.py run1` exits as soon as the exception is raised on 
the main thread. This is the desired behavior in our case.

- `python threadpool_map.py run2` keeps running until the thread worker 
processes all queued work items. The only difference from `run1` is that the 
result of `ThreadPoolExecutor.map()` is assigned to a variable.

- `python threadpool_map.py run3` has a `finally` block that shuts down the 
executor without waiting. Still the worker thread keeps running even after the 
shutdown.

Initially it seemed like https://bugs.python.org/issue36780 but there is no 
change in the behavior after commenting out the `atexit.register(_python_exit)` 
call (for the `run2` case at least).

--
components: Library (Lib)
files: threadpool_map.py
messages: 381433
nosy: gsakkis
priority: normal
severity: normal
status: open
title: Interpreter exit blocks waiting for ThreadPoolExecutor.map
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
Added file: https://bugs.python.org/file49608/threadpool_map.py

___
Python tracker 
<https://bugs.python.org/issue42409>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39640] fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() support

2020-08-23 Thread George Melikov


George Melikov  added the comment:

PR rebased and ready to review.

--

___
Python tracker 
<https://bugs.python.org/issue39640>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Managing plug-ins

2020-05-27 Thread George Fischhof
DL Neil via Python-list  ezt írta (időpont: 2020.
máj. 26., K, 3:10):

> On 26/05/20 11:35 AM, Benjamin Schollnick wrote:
> > Did you ever find anything that met your requirements?
> >
> > If not, I have a prototype that I need to build out some more…
> >
> > https://github.com/bschollnick/PyPlugInMgr
> >
> > I use it for some home grown utilities, but it needs to be fleshed out
> > some more…
> > If you’re interested feel free to take a look.
>
> Thanks.
> Am on-the-road at present, but will take a look...
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list


HI,

I do not understand your requirements fully, but two easy come to mind:
registering function as plugin - you can find metaclass or functional
programing examples in google; keywords: register plugin

And the second one, is to put files to a given place and import them in
runtime, I created a pluggable info monitor which does this: in every
cycles imports the given files as plugins.
https://pypi.org/project/pluggable-info-monitor/

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue27035] Cannot set exit code in atexit callback

2020-05-03 Thread George King


George King  added the comment:

I think we should change the documentation to expand the parenthetical " 
(unless SystemExit is raised)" to a complete explanation of that special case.

--

___
Python tracker 
<https://bugs.python.org/issue27035>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39640] fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() support

2020-02-15 Thread George Melikov


George Melikov  added the comment:

I want to add that it's a usual practice:
- 
https://github.com/libuv/libuv/pull/1580/files/bdd987a9b4347164e31e22d2d5ce06fbb5ebc859
- 
https://rev.ng/gitlab/revng/qemu/commit/6f1953c4c14566d3303709869fd26201828b3ccf

--

___
Python tracker 
<https://bugs.python.org/issue39640>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39640] fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() support

2020-02-15 Thread George Melikov


George Melikov  added the comment:

If there is a way not to sync data - you should use neither fdatasync nor fsync.

So IMHO if someone wants to sync data and want to use fdatasync - I see the 
only way on MacOS is to use fsync().

> Note also that this change will not help to run code with fdatasync() on 
> MacOS without fallbacks in Python code until you drop support of all Python 
> versions older than 3.9.

I agree, but I propose to make this change in 3.9 to get it somewhere in future.

--

___
Python tracker 
<https://bugs.python.org/issue39640>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39640] fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() support

2020-02-15 Thread George Melikov


Change by George Melikov :


--
keywords: +patch
pull_requests: +17893
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18516

___
Python tracker 
<https://bugs.python.org/issue39640>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39640] fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() support

2020-02-15 Thread George Melikov


New submission from George Melikov :

POSIX fdatasync() is similar to fsync() but it tries not to sync non-needed 
metadata. If POSIX OS doesn't have it - it's safe to use fsync() (If we need to 
sync data to disk - we have to use one of these functions).

This change will help to run code with fdatasync() on MacOS without fallbacks 
in Python code.

I'll propose a PR soon.

--
components: IO
messages: 362025
nosy: gmelikov
priority: normal
severity: normal
status: open
title: fall back os.fdatasync() to fsync() on POSIX systems without fdatasync() 
support

___
Python tracker 
<https://bugs.python.org/issue39640>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35164] socket.getfqdn and socket.gethostbyname fail on MacOS

2020-01-10 Thread George Hickman


George Hickman  added the comment:

I came across this today with the same timeout behaviour on macOS 10.14.6.

After some digging I tracked it down to the Search Domains setting of my local 
network, this was set to "local", removing that immediately fixed the issue.

--
nosy: +ghickman

___
Python tracker 
<https://bugs.python.org/issue35164>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: What do you use for slides?

2019-11-16 Thread George Fischhof
Dan Stromberg  ezt írta (időpont: 2019. nov. 15., P,
22:36):

> I mostly use Libreoffice Impress, but I've also tried Google Slides.
>
> I don't think Impress does syntax highlighting out of the box, but there's
> a plugin that claims to.
>
> Also, Google Slides purportedly supports highlighting just by
> cut-and-pasting from a GUI editor/IDE with syntax highlighting.
>
> HTH.
>
> On Fri, Nov 15, 2019 at 9:38 AM Abdur-Rahmaan Janhangeer <
> arj.pyt...@gmail.com> wrote:
>
> > Greetings all,
> >
> > For slides i use https://yhatt.github.io/marp/, but sometimes i want a
> > more
> > stylish tool.
> >
> > What do you use for slides? (besides powerpoint + syntax highlighting
> > included)
> >
> > Thanks!
> >
> > Abdur-Rahmaan Janhangeer
> > http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
> > Mauritius
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi
I use Google drive's slides, plus  https://revealjs.com/

br,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38596] simple example give a Linux core dumped with atk-bridge

2019-10-26 Thread Feștilă George Cătălin

Feștilă George Cătălin  added the comment:

No. I don't have a reproducer script for this issue with Linux OS.
The mytext is a class from another script named my_notepad.
The problem comes with time when I use the menu to change the syntax value, as 
you can see:
self.syntax = mytext(self.text_widget.document())
My code is based on this example from GitHub account lfsando: 
https://github.com/lfsando/notepad/blob/master/highlighter.py maybe has the 
same error.

--

___
Python tracker 
<https://bugs.python.org/issue38596>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38596] simple example give a Linux core dumped with atk-bridge

2019-10-26 Thread Feștilă George Cătălin

New submission from Feștilă George Cătălin :

My simple notepad code with QtWidgets.QPlainTextEdit() give me a crash dump on 
Linux Fedora 30 with python3

Python 3.7.4 (default, Jul  9 2019, 16:32:37) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux

[mythcat@desk pyqt5_examples]$ uname -a
Linux desk 5.3.7-200.fc30.x86_64 #1 SMP Fri Oct 18 20:13:59 UTC 2019 x86_64 
x86_64 x86_64 GNU/Linux

[mythcat@desk pyqt5_examples]$ python3 notepad.py 

** (python3:3077): WARNING **: 11:26:06.007: AT-SPI: Could not obtain desktop 
path or name


** (python3:3077): WARNING **: 11:26:06.029: atk-bridge: GetRegisteredEvents 
returned message with unknown signature

** (python3:3077): WARNING **: 11:26:06.029: atk-bridge: 
get_device_events_reply: unknown signature

** (python3:3077): WARNING **: 11:26:06.029: atk-bridge: 
get_device_events_reply: unknown signature
Traceback (most recent call last):
  File "notepad.py", line 222, in assign_syntax_py
self.syntax = mytext(self.text_widget.document())
NameError: name 'mytext' is not defined
Traceback (most recent call last):
  File "notepad.py", line 222, in assign_syntax_py
self.syntax = mytext(self.text_widget.document())
NameError: name 'mytext' is not defined
Aborted (core dumped)

The code is self.syntax = my_notepad.mytext(self.text_widget.document())

--
components: Interpreter Core
messages: 355408
nosy: catafest
priority: normal
severity: normal
status: open
title: simple example give a Linux core dumped with atk-bridge
type: crash
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue38596>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Newbie question about Python syntax

2019-08-26 Thread Paul St George

On 25/08/2019 02:39, Cameron Simpson wrote:

On 24Aug2019 21:52, Paul St George  wrote:

[snip]>
Aside from "map" being a poor name (it is also a builtin Python 
function), it seems that one creates one of these to control how some 
rendering process is done.


The class reference page you originally cites then specifies the meaning 
of the various attributes you might set on one of these objects.


Cheers,
Cameron Simpson 


Thanks Cameron. As this list has a low noise to signal ratio I cannot 
thank you enough here.


I could have stayed where I belong in Blender Artists, or similar, but 
those lists tend to just offer solutions and as Douglas Adams almost 
said knowledge without understanding is almost meaningless. Here I have 
gained enough understanding (perhaps not to yet make sufficient sense in 
what I say) but to transfer knowledge from solving one problem to 
possibly solving many.


Thank you for your patience and tolerance,

Dr Paul St George
--
http://www.paulstgeorge.com
http://www.devices-of-wonder.com


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


Re: Newbie question about Python syntax

2019-08-24 Thread Paul St George

On 24/08/2019 01:23, Cameron Simpson wrote:

On 23Aug2019 13:49, Paul St George  wrote:

Context:
I am using Python to interrogate the value of some thing in Blender 
(just as someone else might want to use Python to look at an email in 
a Mail program or an image in Photoshop).


Assumptions:
So, I want to look at the attribute of an instance of a class called 
CompositorNodeMapValue. The code in the Python tutorial seems to be 
for creating an instance of a class, but I assume Blender (in my case) 
has already created the instance that I want to interrogate.


That would be the expectation. And to interrogate it, you need that 
instance to hand in a variable.



Question:
If this is so, should I find the code to get a list of the instances 
that have been made (maybe using inspect?) and then, when I have its 
name, the attributes of the one that interests me?


Have you not got one of these handed to you from something?

Or are you right at the outside with some "opaque" blender handle or 
something? (Disclaimer: I've never used Blender.)


Thank you once again.
If I understand your question, I am right outside. By this I mean I have 
not created anything with Python. I have made the Blender model with the 
UI and am trying to use Python to read the values for the settings used. 
This has worked for all settings except this Map Value Node.




You can inspect objects with the inspect module. You can also be more 
direct. Given an object "o", you can do an assortment of things:


Before I do any of the following, I assume I need to use something like:

import struct
class CompositorNodeMapValue(o):

I have tried this. Nothing happens. Not even an error. It's like waiting 
for Godot.


I am guessing I am in the wrong namespace.

I don't know whether it is relevant, but I tried plain
dir()
and
dir(struct)

They each returned a list and neither list had mention of 
CompositorNodeMapValue


If I do something like:
o = CompositorNodeMapValue()
I get:
NameError: name 'CompositorNodeMapValue' is not defined



dir(o) gets a list of its attribute names.

help(o) prints out the docstring, somewhat rendered.

o.__dict__ is usually a dict mapping attribute names to their values.

type(o) gets you its type, so "print(type(o))" or 
"print(type(o).__name__)" can be handy.


A crude probe function (untested):

  def probe(o):
    print(o)
    for attr, value in sorted(o.__dict__.items()):
  print(" ", attr, type(value).__name__, value)

Enjoy,
Cameron Simpson  (formerly c...@zip.com.au)

"Are we alpinists, or are we tourists" followed by "tourists! tourists!"
    - Kobus Barnard  in rec.climbing,
  on things he's heard firsthand



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


[issue37461] email.parser.Parser hang

2019-08-23 Thread George Zhang


Change by George Zhang :


--
pull_requests: +15137
pull_request: https://github.com/python/cpython/pull/15432

___
Python tracker 
<https://bugs.python.org/issue37461>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37461] email.parser.Parser hang

2019-08-23 Thread George Zhang


Change by George Zhang :


--
pull_requests: +15136
pull_request: https://github.com/python/cpython/pull/15430

___
Python tracker 
<https://bugs.python.org/issue37461>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Newbie question about Python syntax

2019-08-23 Thread Paul St George

On 22/08/2019 23:21, Kyle Stanley wrote:
[snip]


The tutorial that Terry was referring to was the one on docs.python.org,
here's a couple of links for the sections he was referring to:

Full section on classes: https://docs.python.org/3/tutorial/classes.html

Section on instantiating objects from classes:
https://docs.python.org/3/tutorial/classes.html#class-objects


[snip]



Aha, thank you all.
Here then, is my first problem.

Context:
I am using Python to interrogate the value of some thing in Blender 
(just as someone else might want to use Python to look at an email in a 
Mail program or an image in Photoshop).


Assumptions:
So, I want to look at the attribute of an instance of a class called 
CompositorNodeMapValue. The code in the Python tutorial seems to be for 
creating an instance of a class, but I assume Blender (in my case) has 
already created the instance that I want to interrogate.


Question:
If this is so, should I find the code to get a list of the instances 
that have been made (maybe using inspect?) and then, when I have its 
name, the attributes of the one that interests me?


Or shall I go into the garden to eat worms?

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


Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George

On 22/08/2019 20:02, Terry Reedy wrote:

On 8/22/2019 3:34 AM, Paul St George wrote:
I have the Python API for the Map Value Node here: 
<https://docs.blender.org/api/current/bpy.types.CompositorNodeMapValue.html>. 



All well and good. Now I just want to write a simple line of code such 
as:


import bpy

...

 >>>print(bpy.types.CompositorNodeMapValue.max[0])

If this works, I will do something similar for max, min, offset and 
then size.


 From this and your other responses, you seem to not understand some of 
the concepts explained in the tutorial, in particular class and class 
instance.  Perhaps you should reread the appropriate section(s), and if 
you don't understand any of the examples, ask about them here.  We are 
familiar with those, but not with CompositorNodeMapValue.




Terry,
You are right, but it is even worse than you think. I do not have a 
tutorial so I have no examples to understand.


Reading Cameron et al, I have broken the problem down into:
do something (probably using the word self) that _gives_ me an instance 
of CompositorNodeMapValue.


Then when I done that,
look at some of the attributes (.max, .min, .offset, .size) of the instance.

Paul

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


[issue37902] Add scrolling for IDLE browsers

2019-08-22 Thread George Zhang


George Zhang  added the comment:

Also, how should I get the new code coverage percentage  (or should it be 
ignored for now)?

I'm thinking of adding a few more tests that send invalid events which would 
raise KeyError but I don't think that this behaviour will be used  (and it's 
not documented). Should it give a more specific error message?

The test for multicall is only targeting the MultiCall class that gets 
returned.  How should it check for any possible subclasses of it?

--

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-22 Thread George Zhang


George Zhang  added the comment:

I renamed mousescroll to handlescroll as it's an independent callback function 
and I think it fits its use case better.  I can keep it as mousescroll if you 
like though.

The handlescroll function is now a standalone module function in tree.py and 
the EditorWindow imports it for use  (instead of creating its own function).  
Its signature is `handlescroll(event, widget=None)` where event is the event 
(yeah...) and widget is an optional argument that overrides the widget to call 
`yview(SCROLL, lines, "units")` on.

The second argument was added so that the nasty labels don't have to use the 
same function but with one line changed  (we redirect handlescroll to use 
`self.canvas` because `event.widget` would refer to the Label which has no 
yview function).

I've added tests on handlescroll with different events.  I've also added a test 
on multicall that checks to test if MultiCallCreator overrides yview.

Sorry about the PR closing and reopening. I was panicking about commiting more 
than once and saw that I should make a new branch for the patch  (instead of 
using master branch).

--

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George

On 22/08/2019 11:49, Cameron Simpson wrote:

On 22Aug2019 09:34, Paul St George  wrote:
I have the Python API for the Map Value Node here: 
<https://docs.blender.org/api/current/bpy.types.CompositorNodeMapValue.html>. 



All well and good. Now I just want to write a simple line of code such 
as:


import bpy

print(bpy.types.CompositorNodeMapValue.max[0])

[...]
AttributeError: type object 'CompositorNodeMapValue' has no attribute 
'max'


CompositorNodeMapValue is a class. All the attributes described are for 
instances of the class. So you need to do something that _gives_ you an 
instance of CompositorNodeMapValue. That instance should have a .max array.


Cheers,
Cameron Simpson 


Gulp. Thank you. I did ask for a pointer but perhaps I need a roadmap.

I have tried to do something that gives me an instance of 
CompositorNodeMapValue. I don't think I should humiliate myself further 
by sharing my attempts so could you please show me what the code should 
look like.


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


Newbie question about Python syntax

2019-08-22 Thread Paul St George
I have the Python API for the Map Value Node here: 
.


All well and good. Now I just want to write a simple line of code such as:

import bpy

...

>>>print(bpy.types.CompositorNodeMapValue.max[0])

If this works, I will do something similar for max, min, offset and then 
size.


I know my embarrassingly feeble attempt is wrong because the console 
tells me:

AttributeError: type object 'CompositorNodeMapValue' has no attribute 'max'

Could anyone (please) point me in the right direction?

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


[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


George Zhang  added the comment:

Looks like my PRs are getting out of hand... This is the final PR :P

--

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests: +15079
pull_request: https://github.com/python/cpython/pull/15368

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests:  -15077

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests:  -15076

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests: +15076
pull_request: https://github.com/python/cpython/pull/15360

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests: +15076, 15077
pull_request: https://github.com/python/cpython/pull/15360

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
pull_requests:  -15072

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


George Zhang  added the comment:

I looked at the code for scrolling and moved it over to the ScrolledCanvas and 
TreeNode (because it uses a Label that sits on the canvas, meaning we have to 
rebind it here).

I haven't figured out how to add the scroll-by-pressing-down-and-moving way but 
I'll look further into it.

About the factoring out part, the ScrolledCanvas and TreeNode are both used by 
the two browsers, meaning that no code has to be added to them. In the future, 
a factory function could be made that when called with a canvas, it returns an 
event callback function that can be bound to the canvas. When called, it 
scrolls depending on the event type and other info.

--

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37902] Add scrolling for IDLE browsers

2019-08-21 Thread George Zhang


Change by George Zhang :


--
keywords: +patch
pull_requests: +15072
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/15360

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: absolute path to a file

2019-08-21 Thread Paul St George

On 21/08/2019 04:09, Grant Edwards wrote:

On 2019-08-21, Richard Damon  wrote:


I think gmane feed the newsgroup comp.lang.python which feeds
python-list@python.org.


No, gmane is a gateway to python-list@python.org.

--
Grant

I use https://mail.python.org/pipermail/python-list/ to confirm that any 
post has gone where it should. And it has.



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


[issue37902] Add scrolling for IDLE browsers

2019-08-20 Thread George Zhang


New submission from George Zhang :

I've just started using IDLE's module/path browsers and they offer a lot! 
Putting aside the issue of them opening in separate windows, they have a small 
change that could be made to improve them.

Both browsers have scrollbars, but (for me at least) I cannot scroll using my 
mouse. I propose adding support for scrolling similar to the editor/shell 
windows.

--
assignee: terry.reedy
components: IDLE
messages: 350043
nosy: GeeVye, terry.reedy
priority: normal
severity: normal
status: open
title: Add scrolling for IDLE browsers
type: enhancement
versions: Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: absolute path to a file

2019-08-20 Thread Paul St George

On 20/08/2019 11:43, Cameron Simpson wrote:

Please remember to CC the list.
Instead of 'Post a followup to this newsgroup' or 'To: 
python-list@python.org'?




On 19Aug2019 22:06, Paul St George  wrote:

On 19/08/2019 14:16, Cameron Simpson wrote:

[...]
There's a remark on that web page I mentioned that suggests that the 
leading '//' indicates the filename is relative to the Blender model, 
so the context directory for the '//' is likely 
/Users/Lion/Desktop/test8.


Yes. That makes sense. The reason I was testing with two images, one 
at /Users/Lion/Desktop/test8/image01.tif and the other at 
/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images 
being in the same folder as the Blender file.


So, let's assume the context directory is /Users/Lion/Desktop/test8
and see how we get on below.

[...]
realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it 
is a special Blender path. First you need to convert it. By replacing 
'//' with the blend file's directory. Then you can call realpath. If 
you still need to.


Understood. Now. Thanks!


[...snip...]


Did you just [...snip...] yourself?


Yes. It keeps the surrounding context manageable. In this way you know 
to which text I am referring, without having to wade through paragraphs 
to guess what may be relevant.



   from os.path import dirname

   # Get this from somewhere just hardwiring it for the example.
   # Maybe from your 'n' object below?
   blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'

Is this setting a relative path?


   blender_image_file = n.image.filename

   unix_image_file = unblenderise(blender_image_file, 
dirname(blend_file))


Now you have a UNIX path. If blend_file is an absolute path, 
unix_image_path will also be an absolute path. But if blend_file is a 
relative path (eg you opened up "tifftest8.blend") unix_image_path 
will be a relative path.


Does unix_image_path = unix_image_file?


Yeah, sorry,  my mistake.


Two possibilities here.
blend_file (and so unix_image_file) is an absolute path OR blend_file 
(and so unix_image_file) is a relative path.


I just want to check my understanding. If I supply the path to 
blend_file then it is absolute, and if I ask Python to generate the 
path to blend_file from within Blender it is relative. Have I got it?


Not quite. What seems to be the situation is:

You've got some object from Blender called "n.image", which has a 
".file" attribute which is a Blender reference to the image file of the 
form "//image01.tif".


I presume that Blender has enough state inside "n" or "n.image" to 
locate this in the real filesystem; maybe it has some link to the 
Blender model of your blend file, and thus knows the path to the blend 
file and since //image01.tif is a reference relative to the blend file, 
it can construct the UNIX path to the file.


You want to know the UNIX pathname to the image file (maybe you want to 
pass it to some unrelated application to view the file or something).


Exactly. I am using Python to log a series of experiments. If I have a 
record of the settings and the assets used, I can better learn from what 
works and so repeat the successes and avoid the failures.


So you need to do what Blender would do if it needs a UNIX path (eg to 
open the file).


The formula for that is dirname(path_to_blendfile) with n.image.file[2:] 
appended to it. So that's what we do with unblenderise(): if the 
filename is a "Blender relative name", rip off the "//" and prepend the 
blend file directory path. That gets you a UNIX path which you can hand 
to any function expecting a normal operating system pathname.


Whether that is an absolute path or a relative path is entirely "does 
the resulting path start with a '/'"?


We used
blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'
So, if I read you correctly, this is an absolute path.

When we used unblenderise on it, out popped a path that was partly but 
not wholly relative. The latter half of the path is relative to the 
absolute first half (/Users/Lion/Desktop/test8/).


/Users/Lion/Desktop/test8/../images/image02.tif

It starts with a slash but cannot be pasted into "Go to...". But maybe 
that is an absolute path in UNIX?




An absolute path starts with a slash and is relative to the root of the 
filesystem. You can use such a path regardless of what your current 
working directory is, because it doesn't use the working directory.




A relative path doesn't start with a slash and is relative to the 
current working directory. It only works if you're in the right working 
directory.


_Because_ a relative path depends on the _your_ working directory, 
usually we pass around absolute paths if we need to tell something else 
about a file, because that will work regardless if what _their_ working 
directory may be.


So, you may well want to turn a relative path into an absolute path

Re: absolute path to a file

2019-08-19 Thread Paul St George

On 19/08/2019 14:16, Cameron Simpson wrote:

On 19Aug2019 08:52, Paul St George  wrote:

On 19/08/2019 01:31, Cameron Simpson wrote:

On 18Aug2019 17:29, Paul St George  wrote:

On 18/08/2019 02:03, Cameron Simpson wrote:
1: Is image01.tif a real existing file when you ran this code?
Yes. image01.tif is real, existing and apparent.
But in what directory? What is its _actual_ full path as you expect 
it to be?


Aha. The Blender file that I am using to test this on has two images 
used as textures. They reside at:

/Users/Lion/Desktop/test8/image01.tif
/Users/Lion/Desktop/images/image02.tif

The Blender file is at /Users/Lion/Desktop/test8/tifftest8.blend


There's a remark on that web page I mentioned that suggests that the 
leading '//' indicates the filename is relative to the Blender model, so 
the context directory for the '//' is likely /Users/Lion/Desktop/test8.


Yes. That makes sense. The reason I was testing with two images, one at 
/Users/Lion/Desktop/test8/image01.tif and the other at 
/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images 
being in the same folder as the Blender file.


So, let's assume the context directory is /Users/Lion/Desktop/test8
and see how we get on below.



(Chris and Peter lead me to believe that Blender has a special kind 
of relative path. The double slashes replace the path to the blend 
file’s directory.) realpath has done something but I know not what.


realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it is 
a special Blender path. First you need to convert it. By replacing '//' 
with the blend file's directory. Then you can call realpath. If you 
still need to.


Understood. Now. Thanks!


[...snip...]


Did you just [...snip...] yourself?


So you might want to write an unBlenderiser (untested example):

 from os.path import isabs, join as joinpath

 def unblenderise(filename, context_dir=None):
   # transmute Blender "relative" path
   if filename.startswith('//'):
 filename = filename[2:]
   if not isabs(filename) and context_dir is not None:
 # attach the filename to `context_dir` if supplied
 filename = joinpath(context_dir, filename)
   return filename

The idea here is to get back a meaningful UNIX path from a Blender 
path. It first strips a leading '//'. Next, _if_ the filename is 
relative _and_ you supplied the optional context_dir (eg the 
directory used for a file brwoser dialogue box), then it prepends 
that context directory.


This _does not_ call abspath or realpath or anything, it just returns 
a filename which can be used with them.


The idea is that if you know where image01.tif lives, you could 
supply that as the context directory.


Yes! Until Peter Otten's timely intervention, I was trying to do this 
and had managed to join the 
path_to_the_folder_that_contains_the_Blender_file to 
the_name_of_the_image (stripped of its preceding slashes).


Your unblenderise looks much better than my nascent saneblender so 
thank you. I will explore more!


Looks like you want wd=os.path.dirname(path_of_blend_file).


Thank you!


Does it depend on knowing where image01.tif lives and manually 
supplying that?


Sort of.

What you've got is '//image01.tif', which is Blender's special notation 
indicating a filename relative to the blend file's directory. All the 
Python library stuff expects an OS path (OS==UNIX on a Mac). So you want 
to convert that into a UNIX path.  For example:


    from os.path import dirname

    # Get this from somewhere just hardwiring it for the example.
    # Maybe from your 'n' object below?
    blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'

Is this setting a relative path?


    blender_image_file = n.image.filename

    unix_image_file = unblenderise(blender_image_file, dirname(blend_file))

Now you have a UNIX path. If blend_file is an absolute path, 
unix_image_path will also be an absolute path. But if blend_file is a 
relative path (eg you opened up "tifftest8.blend") unix_image_path will 
be a relative path.



Does unix_image_path = unix_image_file?

Two possibilities here.
blend_file (and so unix_image_file) is an absolute path OR blend_file 
(and so unix_image_file) is a relative path.


I just want to check my understanding. If I supply the path to 
blend_file then it is absolute, and if I ask Python to generate the path 
to blend_file from within Blender it is relative. Have I got it?




You don't need to use realpath or abspath on that _unless_ you need to 
reference the file from any directory (i.e. _not_ relative to where you 
currently are).


If I decided not to supply the path and so ended up with a relative UNIX 
path, I could now use realpath or abspath to find the absolute path. 
Have I still got it?


#
I combined your unblenderise and your use of it (see below). Is my 
attempt error free?


It works very well. So thank you! I tested it with a Blend file that had 
two images, one in the same folder as the Blen

Re: absolute path to a file

2019-08-19 Thread Paul St George

On 19/08/2019 01:31, Cameron Simpson wrote:

Paul, I can see we must train you in the interleaved response style :-)

On 18Aug2019 17:29, Paul St George  wrote:

On 18/08/2019 02:03, Cameron Simpson wrote:
1: Is image01.tif a real existing file when you ran this code?

Yes. image01.tif is real, existing and apparent.


But in what directory? What is its _actual_ full path as you expect it 
to be?


Aha. The Blender file that I am using to test this on has two images 
used as textures. They reside at:

/Users/Lion/Desktop/test8/image01.tif
/Users/Lion/Desktop/images/image02.tif

The Blender file is at /Users/Lion/Desktop/test8/tifftest8.blend



print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 

'which is at', realpath(n.image.filepath))
gives:
Plane uses image01.tif saved at //image01.tif which is at /image01.tif

(Chris and Peter lead me to believe that Blender has a special kind of 
relative path. The double slashes replace the path to the blend file’s 
directory.) realpath has done something but I know not what.


I expect that realpath has normalised the string '//image01.tif' into 
the normal UNIX path '/image01.tif'. Because realpath works with UNIX 
paths, '//image01.tif' is not the path to an existing file from its 
point of view, because that would be in / ('//' is equivalent to '/' in 
UNIX, because multiple slashes coalesce).



2a:
What is your current working directory when you run this code?

Well, there at least two answers to that question. Within Blender's 
Python Console:

os.getcwd()

‘/‘


Did you run the other code in Blender's Console?


I ran this from Blender's console:
>>>filename = "/Users/Lion/Desktop/test8/readout.py"
>>>exec(compile(open(filename).read(), filename, 'exec'))

I ran os.getcwd() from both within /Users/Lion/Desktop/test8/readout.py
and directly within the Blender console.

>> ‘/‘



The thing to bear in mind is that on many GUI desktops a GUI 
application's working directory may be '/'. Specificly, _not_ your home 
directory. This is because they're invoked (usually) by the desktop 
manager programme. And also because it sidesteps awkward situations like 
having the working directory in some removable medium such as a thumb 
drive, which might get removed.


So the Blender CWD is _not_ your home directory or whatever directory 
your terminal prompt may be in.


And therefore things that depend on the current directory will behave 
counterintuitively. In your case, by getting '/' from os.getcwd().


So: if the image01.tif file is _not_ in '/' (which I expect to be the 
case) then Python's realpath will be doing a lexical operation because 
as far as it is concerned the pathname ('//image01.tif') is not the path 
of an existing file. And its getcwd() isn't what you expect, thus the 
result not being what you want.



But I am *guessing* the real location of the CWD is
/Applications/Blender/blender.app/Contents/Resources/2.79/scripts


This isn't a meaningful statement to me. The CWD is the working 
directory of the python interpreter running your code. If that is the 
Blender Console and the consale says the cwd is '/', then that's what it 
is.


In particular, if you invoke some Python script as /path/to/script.py, 
your cwd does not magicly become '/path/to'.


The cwd is a per process ephemeral thing, which is why the shell "cd" 
command works: it switches the working directory for the shell, and that 
context is inherited by child processes (your commands).


I tried using realpath, bpy.path.abspath, and os.path.abspath on this 
forward slash but nothing changed.


Because the leading slash makes it an absolute path by UNIX rules. The 
cwd never gets a look in; it is irrelevant.



For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd()))


os.path.join is pretty lexical; it largely exists to avoid wiring in an 
OS-dependent path separator into your code (eg Windows' '\\' versus UNIX 
'/' or OS9 ':'). But it notices an absolute path in the sequence and 
discards earlier values, so the second getcwd is kept; not sure why this 
is useful behaviour. But putting an absolute path on the right hand end 
of a join isn't meaningful either, so the result is at best amusing anyway.



2b:
If the underlying OS realpath fails, the Python library function might 
fall back on os.path.join(os.getcwd(), filename).


It should, shouldn’t it. But it doesn’t.


Well, I over simplified. If your path doesn't stat() (== "resolve 
directly to a filesystem object", on which the OS realpath relies), 
Python's realpath seems to be doing a _purely lexical_ path 
normalisation, like os.path.normpath.


So, what have you passed in? '//image01.tif'. That is an absolute path. 
The cwd is not relevant, realpath runs with it as is. 'image01.tif' is 
not in '/', so it doesn't stat(), so we just normalise the path to 
'/image01.tif'.


Alternative values:

'image01.tif' (your n.image.filepath[2:], to skip

[issue37882] Code folding in IDLE

2019-08-18 Thread George Zhang


Change by George Zhang :


--
type:  -> enhancement

___
Python tracker 
<https://bugs.python.org/issue37882>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37882] Code folding in IDLE

2019-08-18 Thread George Zhang


New submission from George Zhang :

Congrats on adding line numbers to IDLE.

With this change, a change to add code folding could be done more easily as the 
folding can reference the line numbers. Many other IDEs have code folding but 
IDLE should also have it.

Code folding could be done with a +/- to the right of the line numbers and can 
show/hide the indented suite under the header (compound statements). It should 
use indentation as tool to figure out which parts can be folded. Blank lines 
don't count. Single line compound statements cannot be folded.

Something like this:

1  - | def spam(ham):
2  - | if ham:
3| eggs()
4| 
5  + | def frob():
8| 
9  - | FOO = (
10   | 1, 2, 3, 4,
11   | 5, 6, 7, 8,
12   | )
13   | 
14   | BAR = (
17   | )
18   | 
19   | if True: print("True")
20   |

--
assignee: terry.reedy
components: IDLE
messages: 349922
nosy: GeeVye, terry.reedy
priority: normal
severity: normal
status: open
title: Code folding in IDLE
versions: Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37882>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: absolute path to a file

2019-08-18 Thread Paul St George

On 18/08/2019 02:03, Cameron Simpson wrote:

On 17Aug2019 11:51, Paul St George  wrote:

print('Track D  from Track B:',os.path.realpath(n.image.filepath))
---Track D  from Track B: /image01.tif

print('Track E  from Track B:',os.path.realpath(n.image.filepath[1:]))
---Track E  from Track B: /image01.tif

print('Track F from Track C:',os.path.realpath(n.image.filepath[2:]))
---Track F from Track C: /image01.tif


I know these may just be cut/paste, but you can shorten this by:

    from os.path import realpath
    print('Track F from Track C:',realpath(n.image.filepath[2:]))

I have 2 other questions:

1: Is image01.tif a real existing file when you ran this code?

realpath kind of expects that - it may do nothing for something which 
doesn't exist. I'd point out that realpath(3), which you get from the 
command "man 3 realpath", says:


    The realpath() function will resolve both absolute and relative 
paths and

    return the absolute pathname corresponding to file_name.  All
    components of file_name must exist when realpath() is called.

Most of the things in the os module are just thin wrappers for the OS 
supplied functions, which is why the MacOS realpath library function is 
relevant.


2: What is your current working directory when you run this code?

If the underlying OS realpath fails, the Python library function might 
fall back on os.path.join(os.getcwd(), filename).


3: What is the airspeed velocity of an unladen swallow?

https://www.python.org/dev/peps/pep-0234/#rationale

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)


1:
Is image01.tif a real existing file when you ran this code?

Yes. image01.tif is real, existing and apparent.

>>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 
'which is at', realpath(n.image.filepath))

gives:
Plane uses image01.tif saved at //image01.tif which is at /image01.tif

(Chris and Peter lead me to believe that Blender has a special kind of 
relative path. The double slashes replace the path to the blend file’s 
directory.) realpath has done something but I know not what.



2a:
What is your current working directory when you run this code?

Well, there at least two answers to that question. Within Blender's 
Python Console:

>>> os.getcwd()
‘/‘

But I am *guessing* the real location of the CWD is
/Applications/Blender/blender.app/Contents/Resources/2.79/scripts

I tried using realpath, bpy.path.abspath, and os.path.abspath on this 
forward slash but nothing changed.


For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd()))

2b:
If the underlying OS realpath fails, the Python library function might 
fall back on os.path.join(os.getcwd(), filename).


It should, shouldn’t it. But it doesn’t. Anyway, wouldn’t this be an 
absolute path via the location of the CWD?



3: What is the airspeed velocity of an unladen swallow?
Do you know the speed and direction of the swallow?



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


Re: absolute path to a file

2019-08-17 Thread Paul St George

On 17/08/2019 15:37, Peter Otten wrote:

Paul St George wrote:


Can someone please tell me how to get the absolute path to a file? I
have tried os.path.abspath. In the code below I have a problem in the
final line (15).

#
|import bpy||


Is this blender? If so the "//" prefix starts making sense:

https://docs.blender.org/api/current/bpy.path.html

I'd try bpy.path.abspath() instead of os.pathabspath().



||import os||
||
||texture_list = []||
||
||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as
outstream:||
||
||
||for obj in bpy.context.scene.objects:||
||for s in obj.material_slots:||
||if s.material and s.material.use_nodes:||
||for n in s.material.node_tree.nodes:||
||if n.type == 'TEX_IMAGE':||
||texture_list += [n.image]||
||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which
is at', os.path.abspath(n.image.filepath), file=outstream)||
|#

This gives me:
---Plane uses image01.tif saved at //image01.tif which is at //image01.tif
---Plane uses image02.tif saved at //../images/image02.tif which is at
//images/image02.tif

But I want an absolute path such as:
---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif
---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif

If it is relevant, my files are on a Mac. Hence the escaped forward slash.




Now following Peter's immensely useful nudge towards bpy.path.abspath(), 
I have learned that Blender uses a special kind of relative path. These 
paths start with ”//” . The double slashes replace the path to the blend 
file’s directory.


This means that py.path.abspath() gives a path that is absolute for most 
of its length then relative towards the end. The good news is that I 
have found a way to tidy this.


os.path.abspath(bpy.path.abspath(p))

This gives a fully absolute file path. The bpy.path.abspath function 
takes care of the ’//’ replacing it with the full path to the file, 
while os.path.abspath takes care of any other unwelcome relative ’../’ 
that might remain.


Thanks to everyone for their help!
Paul

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


Re: absolute path to a file

2019-08-17 Thread Paul St George

On 17/08/2019 16:32, Dennis Lee Bieber wrote:

On Sat, 17 Aug 2019 11:51:47 +0200, Paul St George 
declaimed the following:



  print('Track E  from Track B:',os.path.realpath(n.image.filepath[1:]))
---Track E  from Track B: /image01.tif



Just for giggles, what happens if you preface that with a single
period...

print('Track E  from Track B:',os.path.realpath("." +
n.image.filepath[1:]))





print('Track E for giggles from Track B:',os.path.realpath("." + 
n.image.filepath[1:]))


gives:

Track E for giggles from Track B: /images/blah.tif

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


Re: absolute path to a file

2019-08-17 Thread Paul St George

On 17/08/2019 15:37, Peter Otten wrote:

Paul St George wrote:


Can someone please tell me how to get the absolute path to a file? I
have tried os.path.abspath. In the code below I have a problem in the
final line (15).

#
|import bpy||


Is this blender? If so the "//" prefix starts making sense:

https://docs.blender.org/api/current/bpy.path.html

I'd try bpy.path.abspath() instead of os.pathabspath().



||import os||
||
||texture_list = []||
||
||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as
outstream:||
||
||
||for obj in bpy.context.scene.objects:||
||for s in obj.material_slots:||
||if s.material and s.material.use_nodes:||
||for n in s.material.node_tree.nodes:||
||if n.type == 'TEX_IMAGE':||
||texture_list += [n.image]||
||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which
is at', os.path.abspath(n.image.filepath), file=outstream)||
|#

This gives me:
---Plane uses image01.tif saved at //image01.tif which is at //image01.tif
---Plane uses image02.tif saved at //../images/image02.tif which is at
//images/image02.tif

But I want an absolute path such as:
---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif
---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif

If it is relevant, my files are on a Mac. Hence the escaped forward slash.





Yes, it is Blender and the bpy.path.abspath() works!
And thank you also for the link to the docs. They say:
Returns the absolute path relative to the current blend file using the 
“//” prefix.


So does Blender have its own Python???

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


Re: absolute path to a file

2019-08-17 Thread Paul St George

On 17/08/2019 01:07, Gregory Ewing wrote:
On Sat, Aug 17, 2019 at 2:27 AM Paul St George 
 wrote:



BUT does not work with
| print('test2:',os.path.realpath(n.image.filepath))|

This returns only
|/image01.tif|


What does n.image.filepath look like on its own? If it starts
with a leading slash, then os.path.realpath will think it's
already an absolute path and leave it alone.

The problem then is why it's getting a leading slash in the
first place. It looks like the result of something naively
trying to append a filename to an empty directory path.


Gregory,
Thank you for this. You ask what n.image.filepath looks like on its own. 
Here (below) are some tests and the results: You are right about the 
leading slashes. I have tried to remove them and then use 
os.path.realpath and os.path.abspath but it is as if the slash is still 
there. Perhaps there is a better way to remove the slash - perhaps by 
getting the name of the file. Then I could find the true path to the 
directory that contains the file, and finally join the two together.


But there must be a simpler way?


 print('Track A:',n.image.filepath)
---Track A: //image01.tif

print('Track B:',n.image.filepath[1:])
---Track B: /image01.tif

 print('Track C:',n.image.filepath[2:])
---Track C: image01.tif

 print('Track D  from Track B:',os.path.realpath(n.image.filepath))
---Track D  from Track B: /image01.tif

 print('Track E  from Track B:',os.path.realpath(n.image.filepath[1:]))
---Track E  from Track B: /image01.tif

 print('Track F from Track C:',os.path.realpath(n.image.filepath[2:]))
---Track F from Track C: /image01.tif

 print('Track G from Track C:',os.path.abspath(n.image.filepath[2:]))
---Track G from Track C: /image01.tif

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


Re: absolute path to a file

2019-08-16 Thread Paul St George

On 16/08/2019 18:37, Chris Angelico wrote:

On Sat, Aug 17, 2019 at 2:27 AM Paul St George  wrote:

BUT does not work with
| print('test2:',os.path.realpath(n.image.filepath))|

This returns only
|/image01.tif|


Notes:
Chris, I only mention the extra leading slash on my Mac in case anyone
wonders why it is there. Python puts it there to escape the following slash.


I still don't understand what you mean by that, because there's no
concept of "escaping" with these slashes. It looks like you're
actually working with absolute paths (starting with the leading slash)
when you want to work with relative paths (NOT starting with a leading
slash). The double slash isn't "escaping" anything, to my knowledge,
and Python would not add it.

 From the look of things, you really are getting a valid absolute path
- "/image01.tif" is already absolute. It just isn't the path you want.

ChrisA



Yes, perhaps I am using the wrong terms. I want to find the path that 
looks like this:

/Users/Lion/Desktop/test8/image01.tif

With such a path, I can find the image file. I cannot find the file with 
only /image01.tif


It is safe to ignore what I said about the double forward slashes. I am 
not using these. I only observed their presence and made a guess at 
their meaning.


Paul

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


Re: Re: absolute path to a file

2019-08-16 Thread Paul St George

Thank you Manfred and Cameron!
I think the problem may lie within syntax rather than vocabulary. The 
code works in one place but not where I use it in my script*. Cameron’s 
suggestion works when I try


| print('test1:', os.path.realpath(bpy.data.filepath))|

This returns:
|/Users/Lion/Desktop/test8/tifftest8.blend|


BUT does not work with
| print('test2:',os.path.realpath(n.image.filepath))|

This returns only
|/image01.tif|


Here is my full script:
# starts

|import bpy||
||import os||
||from pathlib import Path ||
||
||texture_list = []||
||
||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as 
outstream:||

||
||
|| for obj in bpy.context.scene.objects:||
||    for s in obj.material_slots:||
||    if s.material and s.material.use_nodes:||
||    for n in s.material.node_tree.nodes:||
||    if n.type == 'TEX_IMAGE':||
||    texture_list += [n.image]||
||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which 
is at', os.path.realpath(n.image.filepath), file=outstream)||


|# ends

Notes:
Chris, I only mention the extra leading slash on my Mac in case anyone 
wonders why it is there. Python puts it there to escape the following slash.
Perhaps I should also mention (in case it is relevant) that I am calling 
my script ‘texturescript.py’ from the Python console of Blender. I use:


|filename = "/Users/Lion/Desktop/test8/texturescript.py"||
||exec(compile(open(filename).read(), filename, 'exec'))|


* My original |os.path.abspath| also works (and doesn’t work) in these 
circumstances. As does Manfred’s: |Path('./myfile').resolve()|.


On 16/08/2019 05:44, Manfred Lotz wrote:

On Fri, 16 Aug 2019 09:00:38 +1000
Cameron Simpson  wrote:


On 15Aug2019 22:52, Manfred Lotz  wrote:

I did this:

>from pathlib import Path

abs_myfile = Path('./myfile').resolve()
which worked fine for me.

There is also os.path.realpath(filename) for this purpose. In modern
Python that also accepts a Pathlike object.

Thanks for this.

I changed my code to use your suggestion which seems to
be better for the situation where I used resolve() before.


--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302

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


absolute path to a file

2019-08-15 Thread Paul St George
Can someone please tell me how to get the absolute path to a file? I 
have tried os.path.abspath. In the code below I have a problem in the 
final line (15).


#
|import bpy||
||import os||
||
||texture_list = []||
||
||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as 
outstream:||

||
||
|| for obj in bpy.context.scene.objects:||
||    for s in obj.material_slots:||
||    if s.material and s.material.use_nodes:||
||    for n in s.material.node_tree.nodes:||
||    if n.type == 'TEX_IMAGE':||
||    texture_list += [n.image]||
||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which 
is at', os.path.abspath(n.image.filepath), file=outstream)||

|#

This gives me:
---Plane uses image01.tif saved at //image01.tif which is at //image01.tif
---Plane uses image02.tif saved at //../images/image02.tif which is at 
//images/image02.tif


But I want an absolute path such as:
---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif
---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif

If it is relevant, my files are on a Mac. Hence the escaped forward slash.

--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

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


Re: How to plot a data including date and time?

2019-08-14 Thread George Fischhof
Elliott Roper  ezt írta (időpont: 2019. aug. 14., Sze
15:56):

> On 14 Aug 2019, Elliott Roper wrote
> (in article<0001hw.23044901039e772c7ca97...@news.giganews.com>):
>
> > On 14 Aug 2019, amirrezaheidary...@gmail.com wrote
> > (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>):
> >
> > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2,
> amirrezah...@gmail.com
> > > wrote:
>
> Oh Damn! Here is an attempt to stop the code running into a single line..
> > >
> > > > I have a .csv file, in first column I have date and hour, and in the
> second
> > > > column I have energy use data. How can I make a bar chart with Date
> and
> > > > time as the x axis and the energy use as the Y axis?
> > > >
> > > > Thanks
> > >
> > > Thank you for your guidance. I am already using matplotlib but I do
> not know
> > > how to import a column of date and time and to use it properly as the x
> > > axis.
> > > can you tell me the code?
> > >
> > > Thanks
>
> >
> > If you don't mind using a steam hammer to crack a nut, it is amazing
> what you
> > can do with pandas using just the "10 minute guide" chapter in the
> (shudder)
> > 10,000 page manual. The chief benefit is how thoroughly it protects you
> from
> > Numpy and Matplotlib.
> > I solved a similar problem (tracking home blood pressure with
> exponentially
> > weighted means) up and running in half a day from a completely cold
> start.
> > The graphing bit is a delight. However, if you want to do something that
> the
> > 10 minute guide does not cover, you can lose a man-month without really
> > trying. Pandas is a beautiful monster!
> >
> > Here's the relevant bit
> >
> > import numpy as np
> >
> > import pandas as pd
> >
> > import matplotlib.pyplot as plt
> >
> >
> > #preparing the csv from a text file elided as irrelevant
> >
> > #except that the .csv headings have to be Date Systolic Diastolic for
> this to
> > work as designed
> >
> > # Plot the intermediate file with pandas after adding exponentially
> weighted
> > means
> >
> > df = pd.read_csv('Blood pressure.csv')
> >
> > df['Date'] = pd.to_datetime(df['Date'])
> >
> > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean()
> >
> > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean()
> >
> > plt.ioff()
> >
> > df.plot(x='Date')
> >
> > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more
> > healthy levels
> >
> > plt.ylabel('mm Hg')
> >
> > plt.suptitle("Home BP record")
> >
> > plt.show()
> >
> > That should give you a start
>
> --
> To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96
> 3CF7
> 637F 896B C810 E199 7E5C A9E4 8E59 E248
>
> --
> https://mail.python.org/mailman/listinfo/python-list




Hi,

Pygal is a very good and easy to use charting library

BR,
George


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


Re: Re: String slices

2019-08-10 Thread Paul St George


On 10/08/2019 17:35, Dennis Lee Bieber wrote:

On Sat, 10 Aug 2019 11:45:43 +0200, "Peter J. Holzer"
declaimed the following:



There are of course many variants to all three methods.

And then one can get downright nasty...


X = 3.14
Y = 2.78
Z = 6.226E23
print("".join(["Plane rotation %s: %s\n" % (nm, vl)

... for (nm, vl) in [("X", X), ("Y", Y), ("Z", Z)]]))
Plane rotation X: 3.14
Plane rotation Y: 2.78
Plane rotation Z: 6.226e+23

(replace "print" with "outstream.write" for use with the file)


|outstream.write| could be very useful, thank you Peter and Cameron 
(neither being Rhodri James). If I wanted to learn more about formatting 
strings is there a better place to go than:


https://docs.python.org/release/3.6.5/library/string.html?highlight=string#format-string-syntax

https://pyformat.info

https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html

And Dennis, whatever you did there is very impressive and works 
perfectly but I don’t know enough to be able to use it. Please will you 
say more or direct me to some reference? I couldn’t find ‘nasty’ in the 
Python docs.

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


Re: Re: String slices

2019-08-09 Thread Paul St George


On 09/08/2019 16:29, Rhodri James wrote:

On 09/08/2019 15:13, Paul St George wrote:

In the code (below) I want a new line like this:

Plane rotation X: 0.0
Plane rotation Y: 0.0
Plane rotation Z: 0.0

But not like this:

Plane rotation X:
0.0
Plane rotation Y:
0.0
Plane rotation Z:
0.0

Is it possible?
(I am using Python 3.5 within Blender.)

#
import os

outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w')

print(

"Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0],

"Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1],

"Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2],

file=outstream, sep="\n"

)

outstream.close()


The 'sep="\n"' parameter to print() means "put a newline between each 
item."  So don't do that.  Put the newlines you do want in explicitly, 
or use separate calls to print():


(I'm abbreviating because I really can't be bothered to type that much 
:-)


  print("X:", thing[0],
    "\nY:", thing[1],
    "\nZ:", thing[2],
    file=outstream)

or

  print("X:", thing[0], file=outstream)
  print("Y:", thing[1], file=outstream)
  print("Z:", thing[2], file=outstream)

I would probably use the latter, but it's just a matter of personal 
preference.


(Actually I would probably use outstream.write() and do my own 
formatting, but let's not get side-tracked ;-)





So, I am going with your second suggestion (see below) but I would love 
to hear your outstream.write() side-track!



import os

with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as outstream:

   plane = bpy.data.objects["Plane"]

   print("Plane rotation X:",plane.rotation_euler[0], file=outstream)

   print("Plane rotation Y:",plane.rotation_euler[1], file=outstream)

   print("Plane rotation Z:",plane.rotation_euler[2], file=outstream)

   print("Focal length:", bpy.context.object.data.lens, file=outstream)

   and so on...




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


Re: Re: Python in Blender. Writing information to a file.

2019-08-09 Thread Paul St George


On 09/08/2019 15:59, Rhodri James wrote:

On 09/08/2019 14:54, Paul St George wrote:


On 09/08/2019 04:09, Cameron Simpson wrote:

On 08Aug2019 22:42, Paul St George  wrote:

On 08/08/2019 10:18, Peter Otten wrote:

The print() function has a keyword-only file argument. So:
with open(..., "w") as outstream:
    print("Focal length:", bpy.context.object.data.lens, 
file=outstream)

[...]



That worked perfectly.

outstream = open(path to my file,'w')
print(
whatever I want to print
file=outstream
)
outstream.close()


I just wanted to point out Peter's use of the open context manager:

   with open(..., "w") as outstream:
 print stuff ...

You'll notice that it does not overtly close the file. The file 
object returned from open() is a context manager, the "with" 
statement arranges to close the file when your programme exits the 
with suite.


Importantly, the close will happen even if the code inside raises an 
exception, which in your "open..print..close" sequence would not 
reach the close call.


So we recommend the "with" form of open() above.

There are circumstances where it isn't useful, but they are very rare.

Cheers,
Cameron Simpson 


I almost understand.

Are you saying I should change the first line of code to something like:

|outstream = with open(path to my file,'w') # this is invalid syntax|

and then delete the

outstream.close()


No, you should do what Peter wrote:

with open("/path/to/file", "w") as outstream:
  print(my_stuff, file=outstream)


Got it! I hadn't taken Peter's advice as code. I thought (well anyway now I 
have it). So thanks to Peter, Cameron and
Rhodri.

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


String slices

2019-08-09 Thread Paul St George

In the code (below) I want a new line like this:

Plane rotation X: 0.0
Plane rotation Y: 0.0
Plane rotation Z: 0.0

But not like this:

Plane rotation X:
0.0
Plane rotation Y:
0.0
Plane rotation Z:
0.0

Is it possible?
(I am using Python 3.5 within Blender.)

#
import os

outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w')

print(

"Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0],

"Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1],

"Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2],

file=outstream, sep="\n"

)

outstream.close()

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


Re: Python in Blender. Writing information to a file.

2019-08-09 Thread Paul St George


On 09/08/2019 04:09, Cameron Simpson wrote:

On 08Aug2019 22:42, Paul St George  wrote:

On 08/08/2019 10:18, Peter Otten wrote:

The print() function has a keyword-only file argument. So:
with open(..., "w") as outstream:
    print("Focal length:", bpy.context.object.data.lens, 
file=outstream)

[...]



That worked perfectly.

outstream = open(path to my file,'w')
print(
whatever I want to print
file=outstream
)
outstream.close()


I just wanted to point out Peter's use of the open context manager:

   with open(..., "w") as outstream:
 print stuff ...

You'll notice that it does not overtly close the file. The file object 
returned from open() is a context manager, the "with" statement 
arranges to close the file when your programme exits the with suite.


Importantly, the close will happen even if the code inside raises an 
exception, which in your "open..print..close" sequence would not reach 
the close call.


So we recommend the "with" form of open() above.

There are circumstances where it isn't useful, but they are very rare.

Cheers,
Cameron Simpson 


I almost understand.

Are you saying I should change the first line of code to something like:

|outstream = with open(path to my file,'w') # this is invalid syntax|

and then delete the

outstream.close()

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


[issue32810] Expose ags_gen and agt_gen in asynchronous generators

2019-08-08 Thread George Zhang


George Zhang  added the comment:

Also, while the PEP first introducing asynchronous generators stated that its 
.asend() and .athrow() methods will return a "coroutine-like object", it 
doesn't allow any introspection into its state or parent async generator.

My workaround was to wrap the .asend() and other methods with another coroutine 
that just awaits and returns the result. Having a better way to check its state 
and frame will bring it closer to a coroutine.

--
nosy: +GeeVye

___
Python tracker 
<https://bugs.python.org/issue32810>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Re: Python in Blender. Writing information to a file.

2019-08-08 Thread Paul St George


On 08/08/2019 10:18, Peter Otten wrote:

Paul St George wrote:


I am using Python 3.5 within Blender. I want to collect values of the
current settings and then write all the results to a file.

I can see the settings and the values in the Python console by doing
this for each of the settings
|
|

|print(“Focal length:”,bpy.context.object.data.lens)|

---Focal length: 35.0


or I can do many at a time like this:

|print("Plane rotation
X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation
Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation
Z:",bpy.data.objects["Plane"].rotation_euler[2])|

---Plane rotation X: 0.0
---Plane rotation Y: 0.0
---Plane rotation Z: 0.0


My question:
How do I write all the results to a file? I have tried file.write but
can only write one argument at a time. Is there a better way to open a
file, write the collected information to it and then close the file?


The print() function has a keyword-only file argument. So:

with open(..., "w") as outstream:
 print("Focal length:", bpy.context.object.data.lens, file=outstream)


|print("Plane rotation
X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation
Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation
Z:",bpy.data.objects["Plane"].rotation_euler[2])|

This looks messy to me. I' probably use intermediate variables

x, y, z = bpy.data.objects["Plane"].rotation_euler
print(
 "Plane rotation X:", x,
 "Plane rotation Y:", y,
 "Plane rotation Z:", z,
 file=outstream, sep="\n"
)

or even a loop.



That worked perfectly.

outstream = open(path to my file,'w')
print(
whatever I want to print
file=outstream
)
outstream.close()



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


Python in Blender. Writing information to a file.

2019-08-08 Thread Paul St George
I am using Python 3.5 within Blender. I want to collect values of the 
current settings and then write all the results to a file.


I can see the settings and the values in the Python console by doing 
this for each of the settings

|
|

|print(“Focal length:”,bpy.context.object.data.lens)|

---Focal length: 35.0


or I can do many at a time like this:

|print("Plane rotation 
X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation 
Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation 
Z:",bpy.data.objects["Plane"].rotation_euler[2])|


---Plane rotation X: 0.0
---Plane rotation Y: 0.0
---Plane rotation Z: 0.0


My question:
How do I write all the results to a file? I have tried file.write but 
can only write one argument at a time. Is there a better way to open a 
file, write the collected information to it and then close the file?


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


[issue37771] No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances

2019-08-06 Thread George Zhang


Change by George Zhang :


--
versions: +Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37771>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37391] MacOS Touchpad scrolling crashes IDLE

2019-06-25 Thread George Pantazes


George Pantazes  added the comment:

In case anyone would like to weigh in on the Homebrew side, I've filed the 
homebrew issue here: https://github.com/Homebrew/homebrew-core/issues/41338 .

--

___
Python tracker 
<https://bugs.python.org/issue37391>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37391] MacOS Touchpad scrolling crashes IDLE

2019-06-25 Thread George Pantazes


George Pantazes  added the comment:

Checked against the python.org installation. In that installation's IDLE, About 
IDLE > Tk version 8.6.8.

So my question is: 
- Is it on me to fix this for my own machine because I should have gotten my 
own more-up-to-date TK before installing Python via Homebrew?
- Or is this a Homebrew installation bug? And should they include a more 
up-to-dat TK with their installation?

--

___
Python tracker 
<https://bugs.python.org/issue37391>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37391] MacOS Touchpad scrolling crashes IDLE

2019-06-25 Thread George Pantazes

George Pantazes  added the comment:

Alright folks, sorry there's going to be a lot of pasted blocks of output, so 
just look for where I @ your name to address your questions.

@ned.deily, here is the output of those info commands.

```
➜ python3 -m test.pythoninfo   
Python debug information


CC.version: Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Py_DEBUG: No (sys.gettotalrefcount() missing)
_decimal.__libmpdec_version__: 2.4.2
builtins.float.double_format: IEEE, little-endian
builtins.float.float_format: IEEE, little-endian
core_config[_disable_importlib]: 0
core_config[allocator]: None
core_config[argv]: ['-m']
core_config[base_exec_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
core_config[base_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
core_config[coerce_c_locale]: 0
core_config[coerce_c_locale_warn]: 0
core_config[dev_mode]: 0
core_config[dump_refs]: 0
core_config[exec_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
core_config[executable]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/python3'
core_config[faulthandler]: 0
core_config[hash_seed]: 0
core_config[home]: None
core_config[ignore_environment]: 0
core_config[import_time]: 0
core_config[install_signal_handlers]: 1
core_config[malloc_stats]: 0
core_config[module_search_path_env]: None
core_config[module_search_paths]: 
['/Users/georgep/Documents/workspace/r-tester/venv/bin/../lib/python37.zip', 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/../lib/python3.7', 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/../lib/python3.7/lib-dynload']
core_config[prefix]: '/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
core_config[program]: 'python3'
core_config[program_name]: 'python3'
core_config[show_alloc_count]: 0
core_config[show_ref_count]: 0
core_config[tracemalloc]: 0
core_config[use_hash_seed]: 0
core_config[utf8_mode]: 0
core_config[warnoptions]: []
core_config[xoptions]: []
datetime.datetime.now: 2019-06-25 10:50:02.453944
expat.EXPAT_VERSION: expat_2.2.6
global_config[Py_BytesWarningFlag]: 0
global_config[Py_DebugFlag]: 0
global_config[Py_DontWriteBytecodeFlag]: 0
global_config[Py_FileSystemDefaultEncodeErrors]: 'surrogateescape'
global_config[Py_FileSystemDefaultEncoding]: 'utf-8'
global_config[Py_FrozenFlag]: 0
global_config[Py_HasFileSystemDefaultEncoding]: 1
global_config[Py_HashRandomizationFlag]: 1
global_config[Py_IgnoreEnvironmentFlag]: 0
global_config[Py_InspectFlag]: 0
global_config[Py_InteractiveFlag]: 0
global_config[Py_IsolatedFlag]: 0
global_config[Py_NoSiteFlag]: 0
global_config[Py_NoUserSiteDirectory]: 0
global_config[Py_OptimizeFlag]: 0
global_config[Py_QuietFlag]: 0
global_config[Py_UTF8Mode]: 0
global_config[Py_UnbufferedStdioFlag]: 0
global_config[Py_VerboseFlag]: 0
locale.encoding: UTF-8
main_config[argv]: 
['/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/test/pythoninfo.py']
main_config[base_exec_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
main_config[base_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
main_config[exec_prefix]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
main_config[executable]: 
'/Users/georgep/Documents/workspace/r-tester/venv/bin/python3'
main_config[install_signal_handlers]: 1
main_config[module_search_path]: 
['/Users/georgep/Documents/workspace/r-tester', 
'/Users/georgep/Documents/workspace/r-tester/venv/lib/python37.zip', 
'/Users/georgep/Documents/workspace/r-tester/venv/lib/python3.7', 
'/Users/georgep/Documents/workspace/r-tester/venv/lib/python3.7/lib-dynload', 
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
 '/Users/georgep/Documents/workspace/r-tester/venv/lib/python3.7/site-packages']
main_config[prefix]: '/Users/georgep/Documents/workspace/r-tester/venv/bin/..'
main_config[warnoptions]: []
main_config[xoptions]: {}
os.cpu_count: 8
os.cwd: /Users/georgep/Documents/workspace/r-tester
os.environ[DISPLAY]: 
/private/tmp/com.apple.launchd.iXqE5VioqF/org.macosforge.xquartz:0
os.environ[HOME]: /Users/georgep
os.environ[LC_CTYPE]: en_US.UTF-8
os.environ[PATH]: 
/Users/georgep/Documents/workspace/r-tester/venv/bin:/Users/georgep/.rvm/gems/ruby-2.5.1/bin:/Users/georgep/.rvm/gems/ruby-2.5.1@global/bin:/Users/georgep/.rvm/rubies/ruby-2.5.1/bin:/Users/georgep/bin:/Users/georgep/.jenv/shims:/Users/georgep/.jenv/bin:/Users/georgep/.jenv/shims:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/munki:/opt/X11/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/georgep/.rvm/bin
os.environ[SHELL]: /bin/zsh
os.environ[TERM]: xterm-256color
os.environ[TMPDIR]: /var/folders/sv/5gh4tk990539nzhdt311pg0h000_fp/T/
os.environ[VIRTUAL_ENV]: /Users/georgep/Documents/workspace/r-tester/venv
os.gid: 20
os.groups: 20, 12, 61, 80, 33, 98, 100, 204, 250, 395, 398, 399

  1   2   3   4   5   6   7   8   9   10   >