Re: Phyton

2016-03-06 Thread Chris Angelico
On Mon, Mar 7, 2016 at 5:45 PM,   wrote:
> As a side note, you are probably aware that if you look at the Linux
> ecosystems there are still a lot of distributions that have Python 2
> as a default. There are still also large mainstream libraries that
> do not (or just very recently) have support for Python 3. For me this
> in particular applied to VTK. I am now finally ready to move to Python 3.

There aren't many mainstream libraries that are still being developed
and don't support Python 3 and don't have equivalents that support
Python 3. There are a reasonable number of third-party modules that
are basically "hey folks, here's the bindings for C++, here's the
bindings for Java, and here's the bindings for Python", where "Python"
has for years meant Py2 only; from what I see of VTK, that seems to be
the case. (It's true of the Google API module, too.) The only way to
get this sort of thing to change is to show these companies that there
is real demand for Python 3 support.

As to Linux distros having Py2 as default - there are two separate
things here. One is that the name "python" will run Python 2, and
Python 3 has to be invoked as "python3". That's stipulated by PEP 394,
and won't be changing. The second concept is of packages being
installed by default, and/or being depended on by critical services.
At the moment, that's more Py2 than Py3, but several distros are
working on migrating (Ubuntu tried hard to have 14.04 ship without Py2
on the main CD ISO, but failed; not sure where they're at now, but
it's definitely the plan), and that's going to start shifting. But for
an application developer, it hardly even matters. If you ship Ruby
code, you declare a dependency on Ruby; if you ship Python code, you
declare a dependency on either Python 2 or Python 3, or "python-any"
or somesuch if you're compatible with both. It's easy enough to have
both Pythons installed on every Linux system that I've ever worked on,
and I rather doubt that that will change.

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


Re: Regex: Perl to Python

2016-03-06 Thread Peter Otten
Fillmore wrote:

> 
> Hi, I'm trying to move away from Perl and go to Python.
> Regex seems to bethe hardest challenge so far.
> 
> Perl:
> 
> while () {
>  if (/(\d+)\t(.+)$/) {
> print $1." - ". $2."\n";
>  }
> }
> 
> into python
> 
> pattern = re.compile(r"(\d+)\t(.+)$")
> with open(fields_Indexfile,mode="rt",encoding='utf-8') as headerfile:
>  for line in headerfile:
>  #sys.stdout.write(line)
>  m = pattern.match(line)
>  print(m.group(0))
>  headerfile.close()
> 
> but I must be getting something fundamentally wrong because:
> 
> Traceback (most recent call last):
>File "./slicer.py", line 30, in 
>  print(m.group(0))
> AttributeError: 'NoneType' object has no attribute 'group'
> 
> 
>   why is 'm' a None?

match() matches from the begin of the string, use search():

match = pattern.search(line)
if match is not None:
print(match.group(1), "-", match.group(2))

Also, in Python you often can use string methods instead of regular 
expressions:

index, tab, value = line.strip().partition("\t")
if tab and index.isdigit():
print(index, "-", value)

> the input data has this format:
> 
>   :
>   3   prop1
>   4   prop2
>   5   prop3
> 


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


Re: Phyton

2016-03-06 Thread marco . nawijn
On Sunday, March 6, 2016 at 6:10:22 PM UTC+1, Mark Lawrence wrote:
> On 06/03/2016 15:28, marco.naw...@colosso.nl wrote:
> > On Sunday, March 6, 2016 at 3:16:19 PM UTC+1, Diego ... wrote:
> >> Hello! I have a question in an exercise that says : Write an expression to 
> >> determine whether a person should or should not pay tax . Consider paying 
> >> tax people whose salary is greater than R $ 1,200.00
> >>
> >> I do not know how to mount the logical expression !!!
> >>
> >> It's like:
> >>
> >> salary = 1250
> >> tax = Not True
> >> salary > 1200 or not tax 
> >
> > Hello Diego,
> >
> > You are looking for the "if" statement. See the link below for
> > the corresponding documentation:
> > https://docs.python.org/2/tutorial/controlflow.html
> >
> > Your example would become something like:
> >
> > salary = 1250.
> > if salary > 1200:
> >  has_to_pay_tax = True
> > else:
> >  has_to_pay_tax = False
> >
> > Marco
> >
> 
> Why in the year 2016 are people still giving links to the Luddite Python 
> 2 docs?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence



On Sunday, March 6, 2016 at 6:10:22 PM UTC+1, Mark Lawrence wrote:
> On 06/03/2016 15:28, marco.naw...@colosso.nl wrote:
> > On Sunday, March 6, 2016 at 3:16:19 PM UTC+1, Diego ... wrote:
> >> Hello! I have a question in an exercise that says : Write an expression to 
> >> determine whether a person should or should not pay tax . Consider paying 
> >> tax people whose salary is greater than R $ 1,200.00
> >>
> >> I do not know how to mount the logical expression !!!
> >>
> >> It's like:
> >>
> >> salary = 1250
> >> tax = Not True
> >> salary > 1200 or not tax 
> >
> > Hello Diego,
> >
> > You are looking for the "if" statement. See the link below for
> > the corresponding documentation:
> > https://docs.python.org/2/tutorial/controlflow.html
> >
> > Your example would become something like:
> >
> > salary = 1250.
> > if salary > 1200:
> >  has_to_pay_tax = True
> > else:
> >  has_to_pay_tax = False
> >
> > Marco
> >
> 
> Why in the year 2016 are people still giving links to the Luddite Python 
> 2 docs?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence


> Why in the year 2016 are people still giving links to the Luddite Python 
>2 docs?

As Ian already mentioned, the Python 2 docs came up as the first hit on
Google. However, I agree with you that for a newcomers to Python a link
to Python 3 would probably have been more appropriate (not that I believe
the content of the sections would be any different). 

As a side note, you are probably aware that if you look at the Linux
ecosystems there are still a lot of distributions that have Python 2
as a default. There are still also large mainstream libraries that
do not (or just very recently) have support for Python 3. For me this
in particular applied to VTK. I am now finally ready to move to Python 3.

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


Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-06 Thread Veek. M
Veek. M wrote:

> 1. What are the rules for using __del__ besides: 'don't use it'.
> 
> 2. What happens when I SystemExit? __del__ and gc are not invoked when
> I SystemExit and there's a circular reference - but why? The OS is
> going to reclaim the memory anyways so why be finicky about circular
> references - why can't we go ahead and call __dell_ and run gc?
> 
> 3.
> import foo
> def __del__(self, foo=foo):
>   foo.bar()
> 
> What happens here to prevent a NameError? Apparently without the
> foo=foo a NameError can occur? But why? import foo creates a reference
> to the object anyways so it's refcount will be above 0 anyways till
> __del__ is called.
> 
> 
> 4. also, are method calls more efficient than function calls?

1,2,3 are a result of reading Beazley - pg 179.

I'll post the relevant paras for 3 first because that's still open, then 
i'll paste the paras for 1,2 for completeness but Chris pretty much 
nailed that. ###'s are my comments.


Text from Beazley for 3:

One final peculiarity about program termination is that the __del__ 
method for some objects may try to access global data or methods defined 
in other modules. Because these objects may already have been destroyed, 
a NameError exception occurs in __del__, and you may get an error such 
as the following:
Exception exceptions.NameError: 'c' in  ignored

If this occurs, it means that __del__ has aborted prematurely. It also 
implies that it may have failed in an attempt to perform an important 
operation (such as cleanly shutting down a server connection). If this 
is a concern, it’s probably a good idea to perform an explicit shutdown 
step in your code, rather than rely on the interpreter to destroy
objects cleanly at program termination.

The peculiar NameError exception can also be eliminated by declaring 
default arguments in the declaration of the __del__()
method:

import foo
class Bar(object):
def __del__(self, foo=foo):
foo.bar()# Use something in module foo

### Why the foo=foo? import foo, would increment the ref-count for 
object 'foo' so why go to all the effort of passing it in to every 
instance via the local stack (ref-to-object-foo)?
---

Text for 1,2 from Beazley:
It’s important to note that in some cases the __del__() method might not 
be invoked at program termination.This can occur if circular references 
exist between objects (in which case objects may be allocated but 
accessible from no known name-space).Although Python’s garbage collector 
can reclaim unused circular references dur-ing execution, it isn’t 
normally invoked on program termination.

### which begs the question, why not on program termination? How bad can 
it be since you are terminating anyway. __del__ seems like a total waste 
product method and given how finicky python is about junk i was 
wondering.. (after all print statement became print builtin so..)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-06 Thread Steven D'Aprano
On Monday 07 March 2016 14:27, Veek. M wrote:

> 1. What are the rules for using __del__ besides: 'don't use it'.

__del__ needs to be defined in a class to be called.

It will be called *at some point* when the instance is about to be garbage 
collected. There is no guarantee when that will be: it might be instantly, 
or a week later.

It may not be called at all, under some obscure circumstances which I don't 
remember.

The presence of a __del__ method may prevent the garbage collector from 
breaking reference cycles, e.g. if A refers to B, and B refers to A, under 
some circumstances if A or B have a __del__ method, the GC may not be able 
to break the cycle and neither object will be collected.

At interpreter shutdown, the __del__ method of objects may be called *after* 
the resources they are relying on have been deleted. See below.

All of these factors are version- and implementation-dependent. In 
particular, remember that IronPython and Jython are based on the .Net CLR 
and JVM, so will use completely different garbage collectors than the 
CPython garbage collector, and so behave slightly differently.


> 2. What happens when I SystemExit? __del__ and gc are not invoked when I
> SystemExit and there's a circular reference - but why? The OS is going
> to reclaim the memory anyways so why be finicky about circular
> references - why can't we go ahead and call __dell_ and run gc?

I'm sorry, I don't understand the GC well enough to answer that question.


> 3.
> import foo
> def __del__(self, foo=foo):
>   foo.bar()
> 
> What happens here to prevent a NameError? Apparently without the foo=foo
> a NameError can occur? But why? import foo creates a reference to the
> object anyways so it's refcount will be above 0 anyways till __del__ is
> called.

I assume that you intended the __del__ method to be inside a class.

Let us see what happens without the local reference:


import foo

class X:
def __del__(self):
foo.bar()

instance = X()
sys.exit()



The `import foo` line creates a module level reference to foo. But during 
interpreter shutdown, the module references may be deleted before the 
__del__ method is called. If that happens, then the code `foo.bar()` will do 
a global lookup for `foo`, and not find it, and you will get a NameError.

The way to fix this is to make the class hold onto a reference to foo. Then, 
even if the module references are deleted, the class reference won't be. 
Either of these ways should work:


class X:
foo = foo  # make foo an attribute of the class itself
def __del__(self):
self.foo.bar()


class X:
def __del__(self, foo=foo):  # make foo a local variable of the method
foo.bar()



> 4. also, are method calls more efficient than function calls?

No. For technical reasons, methods are a thin wrapper around actual 
functions (the "descriptor protocol"). Although it is very fast to create 
that wrapper, it is not instantaneous, so methods are not faster than 
function calls. The difference is very small though, so it is very rare that 
you should need to care about the speed difference. (It is usually dwarfed 
by the function body itself.)

Also, remember that attribute lookups are resolved at runtime:

instance.attr.spam.ham.eggs.cheese.foo.bar.baz.foobar()


needs to do nine lookups at runtime. This includes method calls, so try to 
avoid long chains of "dots". If you are used to Java, you may need to change 
your style of programming:

http://dirtsimple.org/2004/12/python-is-not-java.html




-- 
Steve

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


Re: Regex: Perl to Python

2016-03-06 Thread Rustom Mody
Also for regex hacking:
Try with findall before using match/search
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex: Perl to Python

2016-03-06 Thread Rustom Mody
Also for regex hacking:
Try with findall before using match/search
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex: Perl to Python

2016-03-06 Thread Terry Reedy

On 3/6/2016 11:38 PM, Fillmore wrote:


Hi, I'm trying to move away from Perl and go to Python.
Regex seems to bethe hardest challenge so far.

Perl:

while () {
 if (/(\d+)\t(.+)$/) {
 print $1." - ". $2."\n";
 }
}

into python

pattern = re.compile(r"(\d+)\t(.+)$")
with open(fields_Indexfile,mode="rt",encoding='utf-8') as headerfile:
 for line in headerfile:
 #sys.stdout.write(line)
 m = pattern.match(line)
 print(m.group(0))
 headerfile.close()


Delete this line.  Files opened in a with statement are automatically 
closed when exiting the block.  This is a main motivator and use for the 
with statement.



but I must be getting something fundamentally wrong because:

Traceback (most recent call last):
   File "./slicer.py", line 30, in 
 print(m.group(0))
AttributeError: 'NoneType' object has no attribute 'group'


  why is 'm' a None?


Python has a wonderful interactive help facility.  Learn to use it.

>>> import re
>>> help(re.match)
Help on function match in module re:

match(pattern, string, flags=0)
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.
>>>

Add 'if m is not None:' before accessing m.group.

--
Terry Jan Reedy

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


Re: Regex: Perl to Python

2016-03-06 Thread Chris Angelico
On Mon, Mar 7, 2016 at 3:38 PM, Fillmore  wrote:
> pattern = re.compile(r"(\d+)\t(.+)$")
> with open(fields_Indexfile,mode="rt",encoding='utf-8') as headerfile:
> for line in headerfile:
> #sys.stdout.write(line)
> m = pattern.match(line)
> print(m.group(0))
> headerfile.close()
>
> but I must be getting something fundamentally wrong because:
>
> Traceback (most recent call last):
>   File "./slicer.py", line 30, in 
> print(m.group(0))
> AttributeError: 'NoneType' object has no attribute 'group'
>
>
>  why is 'm' a None?

When the regex doesn't match, Python gives you back None instead of a
match object. Your Perl code has an 'if' to guard that; you can do the
same thing:

if m:
print(m.group(0))

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


Regex: Perl to Python

2016-03-06 Thread Fillmore


Hi, I'm trying to move away from Perl and go to Python.
Regex seems to bethe hardest challenge so far.

Perl:

while () {
if (/(\d+)\t(.+)$/) {
print $1." - ". $2."\n";
}
}

into python

pattern = re.compile(r"(\d+)\t(.+)$")
with open(fields_Indexfile,mode="rt",encoding='utf-8') as headerfile:
for line in headerfile:
#sys.stdout.write(line)
m = pattern.match(line)
print(m.group(0))
headerfile.close()

but I must be getting something fundamentally wrong because:

Traceback (most recent call last):
  File "./slicer.py", line 30, in 
print(m.group(0))
AttributeError: 'NoneType' object has no attribute 'group'


 why is 'm' a None?

the input data has this format:

 :
 3  prop1
 4  prop2
 5  prop3

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


Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-06 Thread Ben Finney
"Veek. M"  writes:

> 1. What are the rules for using __del__ besides: 'don't use it'.

What do you mean by “rules”?

If you want advice on using that method, I don't think a canonical
exhaustive “rules” set exists.

For example: Use ‘__del__’ to mark an object as no longer used; don't
expect that to result in the object actually going away at any
particular point in time.

> 2. What happens when I SystemExit? __del__ and gc are not invoked when
> I SystemExit and there's a circular reference - but why?

So that we can have a concrete example: Can you give a (very minimal and
simple) example demonstrating the behaviour, so we can run it too?

> 3.
> import foo
> def __del__(self, foo=foo):
>   foo.bar()

That appears to be a module-level function. It is not a method of any
class, so I am not clear on how it relates to garbage collection.

> 4. also, are method calls more efficient than function calls?

All method calls are function calls. This is because all methods are
functions.

-- 
 \ “Unix is an operating system, OS/2 is half an operating system, |
  `\Windows is a shell, and DOS is a boot partition virus.” —Peter |
_o__)H. Coffin |
Ben Finney

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


Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-06 Thread Chris Angelico
On Mon, Mar 7, 2016 at 2:27 PM, Veek. M  wrote:
> 1. What are the rules for using __del__ besides: 'don't use it'.

Use it as a last-shot cleanup of resources you own. Don't depend on
it, but use it.

> 2. What happens when I SystemExit? __del__ and gc are not invoked when I
> SystemExit and there's a circular reference - but why? The OS is going
> to reclaim the memory anyways so why be finicky about circular
> references - why can't we go ahead and call __dell_ and run gc?

SystemExit is an exception, same as any other (albeit one that doesn't
inherit from Exception, so it's usually left uncaught); the assumption
is that all resources will be cleaned up on process termination
anyway, so there's no need to run the GC to clean up reference cycles.
It's a total waste of effort.

> 3.
> import foo
> def __del__(self, foo=foo):
>   foo.bar()
>
> What happens here to prevent a NameError? Apparently without the foo=foo
> a NameError can occur? But why? import foo creates a reference to the
> object anyways so it's refcount will be above 0 anyways till __del__ is
> called.

I'm not sure where you're trying to put that code. If you put that at
module level, __del__ won't get called, because there's nothing
special about that name in a module.

During interpreter shutdown, modules will get unloaded, and stuff in
modules will get unloaded. But I'm not even going to _start_
explaining exactly what happens, until I know where this is heading;
there's almost certainly a better way to do this. What is it you're
actually trying to accomplish?

> 4. also, are method calls more efficient than function calls?

No. They in fact *are* function calls, but with a slight bit of magic
so they get their first parameter passed in. You can consider them to
be identical to function calls.

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


__del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-06 Thread Veek. M
1. What are the rules for using __del__ besides: 'don't use it'.

2. What happens when I SystemExit? __del__ and gc are not invoked when I 
SystemExit and there's a circular reference - but why? The OS is going 
to reclaim the memory anyways so why be finicky about circular 
references - why can't we go ahead and call __dell_ and run gc?

3.
import foo
def __del__(self, foo=foo):
  foo.bar()

What happens here to prevent a NameError? Apparently without the foo=foo 
a NameError can occur? But why? import foo creates a reference to the 
object anyways so it's refcount will be above 0 anyways till __del__ is 
called.


4. also, are method calls more efficient than function calls?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Any comment on using ctypesgen package?

2016-03-06 Thread jfong
Mark Lawrence at 2016/3/5  UTC+8 8:01:06PM wrote:
> 
> HTH http://python3porting.com/problems.html

OK, now I understand what "from .cparset import *" means, but it didn't help on 
solving this import error:-(

Thanks for the link, although it seems not help on this problem either:-)

--Jach

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


Re: Phyton

2016-03-06 Thread Chris Angelico
On Mon, Mar 7, 2016 at 10:14 AM, Steven D'Aprano  wrote:
> And I take exception to your use of the word "Luddite" to describe Python 2.
> Python 2 is a perfectly fine programming language, and it will continue to
> be used by some well past 2020. There's no need to bully people into
> upgrading to Python 3, or insult those using Python 2. Python 2 is here for
> the long haul.

I would, however, use the term "legacy" to describe Python 2. It's no
longer the "current stable" version - it's the "old stable", being
maintained at its current state and not advanced further. It's not as
insulting as "Luddite", and more accurate.

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


Re: Phyton

2016-03-06 Thread Larry Martell
On Sun, Mar 6, 2016 at 6:14 PM, Steven D'Aprano  wrote:
> On Mon, 7 Mar 2016 04:05 am, Mark Lawrence wrote:
>
>> Why in the year 2016 are people still giving links to the Luddite Python
>> 2 docs?
>
> Because Python 2.7 is still supported, and will be officially supported
> until 2020, after which it will still have third-party support from
> companies like Red Hat until at least 2023.
>
> And I take exception to your use of the word "Luddite" to describe Python 2.
> Python 2 is a perfectly fine programming language, and it will continue to
> be used by some well past 2020. There's no need to bully people into
> upgrading to Python 3, or insult those using Python 2. Python 2 is here for
> the long haul.

I am an independent contractor and I have worked for 7 companies in
the last 10 years. A total of 1 of those 7 are using python 3. All the
others are using 2.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Phyton

2016-03-06 Thread Steven D'Aprano
On Mon, 7 Mar 2016 04:05 am, Mark Lawrence wrote:

> Why in the year 2016 are people still giving links to the Luddite Python
> 2 docs?

Because Python 2.7 is still supported, and will be officially supported
until 2020, after which it will still have third-party support from
companies like Red Hat until at least 2023.

And I take exception to your use of the word "Luddite" to describe Python 2.
Python 2 is a perfectly fine programming language, and it will continue to
be used by some well past 2020. There's no need to bully people into
upgrading to Python 3, or insult those using Python 2. Python 2 is here for
the long haul.


-- 
Steven

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


Re: Photon mass (was: [Still off-top] Physics)

2016-03-06 Thread Larry Martell
On Sun, Mar 6, 2016 at 4:46 PM, Gene Heskett  wrote:
>
> Has Carol written anything new lately?

I replied to Gene privately, but if anyone is wondering, Carol is my
wife and these are her blogs:

Non-fiction:

http://minervaontheroad.com/

Fiction:

https://minervamartell.wordpress.com/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Photon mass (was: [Still off-top] Physics)

2016-03-06 Thread Gene Heskett
On Sunday 06 March 2016 09:21:49 Larry Martell wrote:

> On Sat, Mar 5, 2016 at 12:36 PM, Gene Heskett  
wrote:

[...]

> > So in that scenario, I have first hand knowledge about relativity
> > despite my offical 8th grade education.
>
> Gene, your massive and varied experiences trump my formal education
> any day.

Chuckle, and many thanks Larry. I'll have to admit that I did get a bit 
of a grin after the fact in explaining the cause of that particular 
broadcasters major pain in the ass to a papered FCC engineer. ;-)  He 
did "get" it FWIW.  He also tore up the $27,500 citation he was going to 
issue because he had measured 46 units of burst in the on air signal the 
night before, when he saw that a diode, which doesn't lie without a huge 
amount of help, said about 19.5 and the R&S monitor worth about 10 grand 
more than what he had in the truck said 39 units. s/b 40.  Since the 
diode measure both sidebands, but the lower one is missing, it only 
shows half of what the NTSC signal has when the monitor (or the common 
tv,) is properly aligned and fine tuned correctly.  We also had 
automatic correctors for that sort of things which would never have 
allowed that 12% error to get past it.

Has Carol written anything new lately?

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Photon mass (was: [Still off-top] Physics)

2016-03-06 Thread Larry Martell
On Sat, Mar 5, 2016 at 12:36 PM, Gene Heskett  wrote:
> On Saturday 05 March 2016 10:46:04 Thomas 'PointedEars' Lahn wrote:
>
>> Gene Heskett wrote:
>> > I've never heard of a massless photon,
>>
>> That is unfortunate as it should be common knowledge by now.
>>
>> > and they do exert a push on the surface they are reflected from, […]
>>
>> Photons exert a force on surfaces because they carry *momentum* or, as
>> it had been understood in terminology that is obsolete now, a non-zero
>> “*relativistic* mass” (that had been distinguished from “rest mass”).
>>
> To have "momentum" imply's mass in the real, we can measure it world.
>
> However with my lack of education, I have a hard time reconciling that
> they travel at C speed, when the classical math says that anything with
> mass traveling at C speed will have aborbed enough energy in getting to
> C speed, that its mass is then infinite. But its obviously not.
>
> I once used relativity to explain to a degree'd FCC engineer exactly why
> a UHF transmitter that used klystrons for amnplifiers, alway had a
> backgound audio buzz. At the moment this was taking place, the station
> was crippled as we'd had a circuit breaker failure, single phasing and
> stopping the cooling water pump, which in turn destroyed the klystron
> used as a visual amplifier (one circuit breaker boom as the building
> went dark when the tube filled with steam, byby $120,000 USD), so just
> to stay on the air, I had moved a weak & about used up klystron from the
> aural cabinet to the visual cabinet, and tee connected the aural drive
> into the visual drive.
>
> When the engineer came in the door, one of the first things he had
> noticed when he monitored the station from about 15 miles away the
> previous evening, was that we were a UHF, but didn't have that annoying
> background buzz in the sound.  So I had to explain it.
>
> What we were observing was that by combining the two carrier signals into
> one tube, meant that both signals were being treated equally to the
> phenomenon they had called incidental carrier phase modulation, and its
> created in the amplitude modulated signal because the 4 foot long
> electron beam is traveling at a speed where speed vs mass is beginning
> to make itself measureable. Said simply, the tube amplifies the signal
> by nominally 30db, by introducing an electrical field across the input
> cavities gap that alternately speeds up, or slows down, an electron
> traverseing that gap with a 20 kilovolt induced speed. 4 feet and  3
> more cavities later, those electrons are now bunched up, the ones in
> front slowing to fall into the bunch, and the ones behind being pushed
> to catch up with the bunch. That induces, because the beam is something
> north of 5 amps, a considerable amount of power in the last cavity which
> can be coupled back out and sent to the antenna, typically about 30 kw.
>
> However, because this beam of electrons is traveling fast enough for
> relativity to come into play, the energy applied to speed the beam up
> encounters an electron with higher mass as it accelerates, whereas the
> energy applied to slow it encounters an electron with lower mass, so the
> deceleration is fractionally greater.  IOW, its not perfectly
> symetrical, the net effect being that the average speed of the beam is
> instantaneous power level dependent, the tube being effectively,
> physically longer, with a longer transit time as the power level rises.
> This is efffectively a frequency modulation, and an unwanted effect.
>
> Some circuits, once the cause of the phenom was known, were designed to
> predistort this by intruducing an opposing FM and cancel it, but by then
> the heyday of the klysron amplifier was coming to an end because of its
> horrible efficiency, that 30 kw of output came at a cost of a few hairs
> over 100kw in the beam supply, making a UHF transmitter the local power
> companies largest customer by a fairly wide margin. That tramsitter used
> nearly 200 kw for every hour it was on the air, and multi-thousand
> dollar power bills were getting the bean counters attention.
>
> But when both signals, visual and aural, are subjected to the same
> effect, AND the sound detection is based on the FM of the 4.5 megahertz
> difference, it cancels out in the receiver. Later, while still operating
> crippled, I made some aural signal to noise measurements, finding truely
> amazing figures of nearly 80 db with video still applied, where when
> operating with 2 klystrons as intended, it was hard put to make a bit
> over 50 db.  It was such a problem that the FCC allowed us to make those
> measurements with the baseband video cable unplugged when doing a proof
> of performance, required for license renewal every 5 years back in those
> days.
>
> So in that scenario, I have first hand knowledge about relativity despite
> my offical 8th grade education.

Gene, your massive and varied experiences trump my formal education any day.

>Photons not having a 

Re: IDLE question: "you may still have to reload nested modules."

2016-03-06 Thread Terry Reedy

On 3/6/2016 7:24 AM, alien2u...@gmail.com wrote:

Hello list,

I am following "Learning Python: Mark Lutz" and came across following
in chapter 3 few days back.


What is the copyright date on the copy you have?


[quote] * You may still have to reload nested modules. Technically
speaking, IDLE's Run->Run Module menu option always runs the current
version of the top-level file only; imported files may still need to
be interactively reloaded when changed. ... [/quote]

It is slightly confusing, as to what it does imply. Could any IDLE
guru clarify if I am missing or overlooking something?


IDLE currently, in its default mode, runs a module in a fresh separate 
process with a fresh sys.modules.  It closely simulates running a module 
from the command line with 'python -m mymodule'.  (One difference is 
that sys.modules is initially larger when run by IDLE.)


The quoted statement must have been written when IDLE always ran user 
code in the persistent IDLE process, as it still does if one starts IDLE 
with the -n option.  The current IDLE doc, in section 3.3. 'Running 
without a subprocess' (with -n) ends with


"Also, the environment is not restarted when Run/Run Module (F5) is 
selected.  If your code has been modified, you must reload() the 
affected modules and re-import any specific items (e.g. from foo import 
baz) if the changes are to take effect.  For these reasons, it is 
preferable to run IDLE with the default subprocess if at all possible."


Even if there were an attempt to restore sys.modules on F5, the comment 
would still apply if one edited and saved an stdlib module imported by 
IDLE.  I run into this when I edit an idlelib file.  I can run tests on 
the file in a separate process with F5, but to verify that the edit has 
the intended effect on IDLE itself, I have to restart IDLE itself.


If the quoted statement is in the most recent version of the book, it 
should be changed in the next one.



If a needed-by-top-level-file module was changed after 'Run->Run
Module', it would any way need to be reloaded.

If it was changed between two "Run->Run Module" actions, won't it be
automatically loaded afresh as a part of restarting Python
interpreter and executing top-level-file [where is the question of
reloading then?]?

[Side observation: though F5 or "Run->Run Module" restarts Python
interpreter with top-level-file afresh [indicated by dir() content
before and after], the command history is not reset during this.


Commands are entered into and kept in the Shell in the IDLE process. 
There are not erased unless one closes Shell.  If there is an editor 
window that keeps IDLE running, and one hits F5, IDLE creates a new 
Shell with no history.



This
likely confirms the GUI process being separate than interpreter.]


The GUI process has its own interpreter, but you are correct that the 
user interpreter is normally separate.


--
Terry Jan Reedy

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


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze

On 06.03.2016 19:51, Tim Chase wrote:

So it looks like one needs to either

results = reversed(list(zip(...)))

or, more efficiently (doing it with one less duplication of the list)

results = list(zip(...))
results.reverse()


Nice idea. :) Unfortunately, I used it while drafting some unittests and 
I love SHORT oneliners:


for c in reversed(zip(ascii_lowercase, ascii_uppercase)):
...

ooops. :-/

Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze

On 06.03.2016 19:53, Peter Otten wrote:

Sven R. Kunze wrote:


what's the reason that reversed(zip(...)) raises as a TypeError?

Would allowing reversed to handle zip and related functions lead to
strange errors?

In Python 3 zip() can deal with infinite iterables -- what would you expect
from

reversed(zip(count()))

?


Have I no idea. ;-)

But to me, "infinite" feels not like the most common use-case to most 
developers.


I just stumbled over it during rapid test case development:

for c in reversed(zip(ascii_lowercase, ascii_uppercase)):
...

Bam! That doesn't work although the code clearly describes what to do. :-(




If all arguments of zip() are finite and of equal length you can write

zip(reversed(a1), reversed(a2), ...)

or if you find that really useful something like


class myzip(zip):

... def __init__(self, *args):
... self.args = args
... def __reversed__(self):
... return zip(*(reversed(a) for a in self.args))
...

list(reversed(myzip("abc", [1,2,3])))

[('c', 3), ('b', 2), ('a', 1)]

While this might look right at first sight it really opens a can of worms.
First zip():


z = zip("abc", "def")
next(z)

('a', 'd')

list(z)

[('b', 'e'), ('c', 'f')]

Now myzip():


m = myzip("abc", "def")
next(m)

('a', 'd')

list(reversed(m))

[('c', 'f'), ('b', 'e'), ('a', 'd')]

Frankly, I have no idea what consistent behaviour should look like for a
zip() that can be "reverse-iterated".

PS: In Python 2 zip() would produce a list, so


list(reversed(zip("abc", "def")))

[('c', 'f'), ('b', 'e'), ('a', 'd')]

worked without requiring any code in zip().



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


Re: Phyton

2016-03-06 Thread Mark Lawrence

On 06/03/2016 17:20, Ian Kelly wrote:

On Sun, Mar 6, 2016 at 10:05 AM, Mark Lawrence  wrote:

Why in the year 2016 are people still giving links to the Luddite Python 2
docs?


Maybe because it's the version that comes up when googling for "python
if statement".



The obvious solution is to take down all the Python 2 stuff so people 
can only find Python 3, problem solved.


Hears screams of anguish despite having ears firmly closed :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread MRAB

On 2016-03-06 18:29, Sven R. Kunze wrote:

Hi,

what's the reason that reversed(zip(...)) raises as a TypeError?

Would allowing reversed to handle zip and related functions lead to
strange errors?


'reversed' yields the items in reverse order; it needs the last item first.

Iterators yield items from the first to the last.

'reversed' would have to get and store all of the items from the 
iterator. It won't know which is the last item until the iterator raises 
StopIteration.


Only then will it be able to yield the items in reverse order.

It's much better for it to complain, and leave it for the user to do it 
explicitly with reversed(list(zip(...))).


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


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Peter Otten
Tim Chase wrote:

> On 2016-03-06 19:29, Sven R. Kunze wrote:
>> what's the reason that reversed(zip(...)) raises as a TypeError?
>> 
>> Would allowing reversed to handle zip and related functions lead to
>> strange errors?
> 
> Peculiar, as this works in 2.x but falls over in 3.x:
> 
> $ python
> Python 2.7.9 (default, Mar  1 2015, 12:57:24)
> [GCC 4.9.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 list(reversed(zip(range(10), range(20,100
> [(9, 29), (8, 28), (7, 27), (6, 26), (5, 25), (4, 24), (3, 23), (2,
> 22), (1, 21), (0, 20)]
> 
> $ python3
> Python 3.4.2 (default, Oct  8 2014, 10:45:20)
> [GCC 4.9.1] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 list(reversed(zip(range(10), range(20,100
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: argument to reversed() must be a sequence
> 
> 
> I'm not sure why reversed() doesn't think that the thing returned by
> zip() isn't a sequence.

Because it isn't ;)

[Python 3]

>>> zip("abc")


>>> import collections
>>> isinstance(z, collections.Sequence)
False
>>> isinstance(z, collections.Iterator)
True

zip() in Python 3 is what itertools.izip() used to be in Python 2.

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


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Tim Chase
On 2016-03-06 12:38, Tim Chase wrote:
> On 2016-03-06 19:29, Sven R. Kunze wrote:
> > what's the reason that reversed(zip(...)) raises as a TypeError?
> 
> I'm not sure why reversed() doesn't think that the thing returned by
> zip() isn't a sequence.

Ah, a little more digging suggests that in 2.x, zip() returned a list
which "has a __reversed__() method [and] supports the sequence
protocol (the __len__() method and the __getitem__() method with
integer arguments starting at 0)."

In 3.x, zip() returns a generic iterator which neither has a
__reversed__() method nor has __len__() and __getitem__() methods.

So it looks like one needs to either

   results = reversed(list(zip(...)))

or, more efficiently (doing it with one less duplication of the list)

   results = list(zip(...))
   results.reverse()

-tkc


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


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Peter Otten
Sven R. Kunze wrote:

> what's the reason that reversed(zip(...)) raises as a TypeError?
> 
> Would allowing reversed to handle zip and related functions lead to
> strange errors?

In Python 3 zip() can deal with infinite iterables -- what would you expect 
from 

reversed(zip(count()))

?

If all arguments of zip() are finite and of equal length you can write

zip(reversed(a1), reversed(a2), ...)

or if you find that really useful something like

>>> class myzip(zip):
... def __init__(self, *args):
... self.args = args
... def __reversed__(self):
... return zip(*(reversed(a) for a in self.args))
... 
>>> list(reversed(myzip("abc", [1,2,3])))
[('c', 3), ('b', 2), ('a', 1)]

While this might look right at first sight it really opens a can of worms. 
First zip():

>>> z = zip("abc", "def")
>>> next(z)
('a', 'd')
>>> list(z)
[('b', 'e'), ('c', 'f')]

Now myzip():

>>> m = myzip("abc", "def")
>>> next(m)
('a', 'd')
>>> list(reversed(m))
[('c', 'f'), ('b', 'e'), ('a', 'd')]

Frankly, I have no idea what consistent behaviour should look like for a 
zip() that can be "reverse-iterated".

PS: In Python 2 zip() would produce a list, so

>>> list(reversed(zip("abc", "def")))
[('c', 'f'), ('b', 'e'), ('a', 'd')]

worked without requiring any code in zip().

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


RE: reversed(zip(...)) not working as intended

2016-03-06 Thread Albert-Jan Roskam
(Sorry for top-posting)

 No TypeError here:

Python 2.7.2 (default, Nov  2 2015, 01:07:37) [GCC 4.9 20140827 (prerelease)] 
on linux4
Type "help", "copyright", "credits" or "license" for more information.
>>> ten = range(10)
>>> reversed(zip(ten, ten))

>>> list(reversed(zip(ten, ten)))
[(9, 9), (8, 8), (7, 7), (6, 6), (5, 5), (4, 4), (3, 3), (2, 2), (1, 1), (0, 0)]
>>>

> To: python-list@python.org
> From: srku...@mail.de
> Subject: reversed(zip(...)) not working as intended
> Date: Sun, 6 Mar 2016 19:29:59 +0100
> 
> Hi,
> 
> what's the reason that reversed(zip(...)) raises as a TypeError?
> 
> Would allowing reversed to handle zip and related functions lead to 
> strange errors?
> 
> Best,
> Sven
> -- 
> https://mail.python.org/mailman/listinfo/python-list
  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Tim Chase
On 2016-03-06 19:29, Sven R. Kunze wrote:
> what's the reason that reversed(zip(...)) raises as a TypeError?
> 
> Would allowing reversed to handle zip and related functions lead to 
> strange errors?

Peculiar, as this works in 2.x but falls over in 3.x:

$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> list(reversed(zip(range(10), range(20,100
[(9, 29), (8, 28), (7, 27), (6, 26), (5, 25), (4, 24), (3, 23), (2,
22), (1, 21), (0, 20)]

$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> list(reversed(zip(range(10), range(20,100
Traceback (most recent call last):
  File "", line 1, in 
TypeError: argument to reversed() must be a sequence


I'm not sure why reversed() doesn't think that the thing returned by
zip() isn't a sequence.

-tkc

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


reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze

Hi,

what's the reason that reversed(zip(...)) raises as a TypeError?

Would allowing reversed to handle zip and related functions lead to 
strange errors?


Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Phyton

2016-03-06 Thread Ian Kelly
On Sun, Mar 6, 2016 at 10:05 AM, Mark Lawrence  wrote:
> Why in the year 2016 are people still giving links to the Luddite Python 2
> docs?

Maybe because it's the version that comes up when googling for "python
if statement".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Phyton

2016-03-06 Thread Mark Lawrence

On 06/03/2016 15:28, marco.naw...@colosso.nl wrote:

On Sunday, March 6, 2016 at 3:16:19 PM UTC+1, Diego ... wrote:

Hello! I have a question in an exercise that says : Write an expression to 
determine whether a person should or should not pay tax . Consider paying tax 
people whose salary is greater than R $ 1,200.00

I do not know how to mount the logical expression !!!

It's like:

salary = 1250
tax = Not True
salary > 1200 or not tax 


Hello Diego,

You are looking for the "if" statement. See the link below for
the corresponding documentation:
https://docs.python.org/2/tutorial/controlflow.html

Your example would become something like:

salary = 1250.
if salary > 1200:
 has_to_pay_tax = True
else:
 has_to_pay_tax = False

Marco



Why in the year 2016 are people still giving links to the Luddite Python 
2 docs?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Phyton

2016-03-06 Thread Mark Lawrence

On 05/03/2016 15:41, Diego ... wrote:

Hello! I have a question in an exercise that says : Write an expression to 
determine whether a person should or should not pay tax . Consider paying tax 
people whose salary is greater than R $ 1,200.00

I do not know how to mount the logical expression !!!

It's like:

salary = 1250
tax = Not True
salary > 1200 or not tax 



Start here 
https://docs.python.org/3/tutorial/controlflow.html#if-statements.  You 
won't need your 'tax' variable if all you're doing is deciding whether 
or not they pay tax.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Regarding installation of python-3.5.1

2016-03-06 Thread Mark Lawrence

On 06/03/2016 06:35, Roshan S Sontakke wrote:

Gud afternoon sir my self Roshan sontakke I have down loaded a setup of 
python-3.5.1 but nt able to install it gives an error message



Please read this http://www.catb.org/esr/faqs/smart-questions.html and 
then have a go at providing us with the data that we need to help you. 
What OS?  What is the precise error message?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Python 3.5.1 (32-bit)_20160306131105

2016-03-06 Thread Mark Lawrence

On 06/03/2016 05:32,  wrote:

when I am installing Python 3.5.1 (32-bit)??some problems occurred.I hope you 
could offer me some help.This file may contain some information about the error.



This type of question has been asked and answered repeatedly over the 
last few months, so please search the archives.  As is often the case 
there is no file with your message.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: ???

2016-03-06 Thread Mark Lawrence

On 04/03/2016 23:26, kyleolson1...@gmail.com wrote:

I cant figure out how to get to the program so I can write code. started and 
introductory programming class for college and im unable to figure out how to 
open this program on my computer. please help if you can, your time would be 
much appreciate.



Please read this http://www.catb.org/esr/faqs/smart-questions.html and 
possibly this http://www.sscce.org/.  Then provide us with the detail 
that we need to asist you.  What OS?  What Python version?  What program 
are you trying to open, IDLE?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Regarding installation of python-3.5.1

2016-03-06 Thread Grant Edwards
On 2016-03-06, Steven D'Aprano  wrote:
> On Sun, 6 Mar 2016 05:35 pm, Roshan S Sontakke wrote:
>
>> Gud afternoon sir my self Roshan sontakke I have down loaded a setup of
>> python-3.5.1 but nt able to install it gives an error message
>
> Shall we guess what the error message says, or would you like to tell us?

I shan't guess at the error message, but I'll take a guess at the
underlying: He's trying to install 3.5 on Windows XP.  XP is too old
for Python 3.5 and he needs to install 3.4.

-- 
Grant

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


Re: Adding Icon To Tkinter Window - Followup

2016-03-06 Thread Wildman via Python-list
On Sun, 06 Mar 2016 10:16:55 +0100, Christian Gollwitzer wrote:

> Am 06.03.16 um 06:53 schrieb Wildman:
>> On Sat, 05 Mar 2016 19:36:19 +0100, Christian Gollwitzer wrote:
>>> import Tkinter
>>> from Tkinter import Tk
>>> root = Tk()
>>> img = Tkinter.Image("photo", file="appicon.gif")
>>> root.call('wm','iconphoto',root._w,img)
>>
>> The above worked perfectly.  Thank you very much.
> 
> Then you should try if it works also with the last line replaced as
> 
>   root.wm_iconphoto(True, img)

That does not work...

$ ./makexface.py
Traceback (most recent call last):
  File "./makexface.py", line 236, in 
root.wm_iconphoto(True, img)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1897, in __getattr__
return getattr(self.tk, attr)
AttributeError: wm_iconphoto

> (as Serhiy and Terry wrote). My system python which I used to test this 
> was just too old to wrap iconphoto, yours should be up to date.
> 
>   Christian
> 
> 
>> According to "root.eval('info patchlevel')" I have version 8.6.2.
>> PNG worked.  That is good because PNG is a common file type for
>> Linux icons.
> 
> PS: 8.6.2 is from mid 2014, that's OK - though we've had a brand new 
> release (8.6.5) in February 2016

I am using the latest release that is offered in the Debian
repository but I will look into upgrading from other sources.

Thanks for the info.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLite

2016-03-06 Thread Klaus Jantzen
   On 02/22/2016 09:32 AM, Klaus Jantzen wrote:

On 02/21/2016 10:37 PM, Albert-Jan Roskam wrote:

  (Sorry for top posting)

  IIRC, you have to do
  sudo apt-get install build-essential python-dev
  ... then re-compile python

  > To: [[1]1]python-list@python.org
  > From: [[2]2]k.d.jant...@mailbox.org
  > Subject: SQLite
  > Date: Sun, 21 Feb 2016 18:11:18 +0100
  >
  > Hello,
  >
  > I have downloaded Python3.5.1 as .targz, compiled it(configure,
  make,...)
  > and it works
  > (under Debian Wheezy AMD64) up to the moment I wanted to use SQLite.
  >
  > I get the following message:
  > ===
  > jantzen@PC4:~$ python
  > Python 3.5.0 (default, Dec  2 2015, 14:16:16)
  > [GCC 4.7.2] on linux
  > Type "help", "copyright", "credits" or "license" for more information.
  > >>> import sqlite3
  > Traceback (most recent call last):
  >   File "", line 1, in 
  >   File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in
  > 
  >     from sqlite3.dbapi2 import *
  >   File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in
  
  >     from _sqlite3 import *
  > ImportError: No module named '_sqlite3'
  > ===
  >
  > Obviously something is missing.
  > How do I solve the problem? Where do I find this module?
  >
  > Thanks for a hint.
  > --
  >
  > K.D.J.
  > --
  > [3][3]https://mail.python.org/mailman/listinfo/python-list

Hello,

thanks for your hint.
That did it!!!

   At least on one machine!!!

--

K.D.J.

 References

Visible links
1. [4]mailto:python-list@python.org
2. [5]mailto:k.d.jant...@mailbox.org
3. [6]https://mail.python.org/mailman/listinfo/python-list

   On the second machine  (DELL E6530) I have everything in the installation
   directory (the expansion of the tarball): sqlite directory with all the
   modules.
   I ran the apt-get install as suggested above.
   I ran './configure --enable-loadable-sqlite-extensions' and find the
   appropriate entry in the
   configure.log.
   I ran 'make' and find the configure option in the Makefile.
   But when running 'make test' the sqlite test fails  with 'no _sqlite3
   module' 

   Any helpful ideas?
   Thanks.
   --

   K.D.J.

References

   Visible links
   1. mailto:1]python-list@python.org
   2. mailto:2]k.d.jant...@mailbox.org
   3. https://mail.python.org/mailman/listinfo/python-list
   4. mailto:python-list@python.org
   5. mailto:k.d.jant...@mailbox.org
   6. https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Phyton

2016-03-06 Thread BartC

On 06/03/2016 15:28, marco.naw...@colosso.nl wrote:

On Sunday, March 6, 2016 at 3:16:19 PM UTC+1, Diego ... wrote:

Hello! I have a question in an exercise that says : Write an expression to 
determine whether a person should or should not pay tax . Consider paying tax 
people whose salary is greater than R $ 1,200.00

I do not know how to mount the logical expression !!!

It's like:

salary = 1250
tax = Not True
salary > 1200 or not tax 


Hello Diego,

You are looking for the "if" statement. See the link below for
the corresponding documentation:
https://docs.python.org/2/tutorial/controlflow.html

Your example would become something like:

salary = 1250.
if salary > 1200:
 has_to_pay_tax = True
else:
 has_to_pay_tax = False


The OP mentioned finding an expression. So perhaps:


has_to_pay_tax = salary > 1200

--
Bartc



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


Re: Phyton

2016-03-06 Thread marco . nawijn
On Sunday, March 6, 2016 at 3:16:19 PM UTC+1, Diego ... wrote:
> Hello! I have a question in an exercise that says : Write an expression to 
> determine whether a person should or should not pay tax . Consider paying tax 
> people whose salary is greater than R $ 1,200.00
> 
> I do not know how to mount the logical expression !!!
> 
> It's like:
> 
> salary = 1250
> tax = Not True
> salary > 1200 or not tax 

Hello Diego,

You are looking for the "if" statement. See the link below for
the corresponding documentation:
   https://docs.python.org/2/tutorial/controlflow.html

Your example would become something like:

salary = 1250.
if salary > 1200:
has_to_pay_tax = True
else:
has_to_pay_tax = False

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


Re: password and username code

2016-03-06 Thread Ömer sarı
5 Mart 2016 Cumartesi 23:52:58 UTC+2 tarihinde Ömer sarı yazdı:
> hi , all , l m fresh user and l m trying to learn python by doing practice 
> but l got stuck in that , l need help , l m a beginner and  l learn some 
> basic things so far so, plz take in consideration that before command .
> 
> here is my code trial:
> #login by using username and password
> 
> loop=1
> 
> paword=['1234','5678']
> pawordch=["1","2","3","4","5","6","7","8","9","0","/","(",")","*","%","&","!","a","b","c","d","e","f","g","h","k","l","m","n","o","p","r","s","t","y","v","y","z","x"]
> name=['murat','can','omer','owrasa']
> 
> while loop==1 :
> print "welcome my website,plz if you have an account , just login , 
> otherwise , register plz"
> username=raw_input("username:")
> password=raw_input("password:")
> if username in name and password in paword:
> print "login is successful, and continue page 2"
> else :
> print" please register"
> login_username=raw_input ("username:")
> login_password=raw_input("password:")
> for login_password in pawordch:
> if login_password in pawordch :
> name.append(login_username)
> paword.append(login_password)
> print "relogin ,plz"
> print name ,"",paword
> login_username=raw_input ("username:")
> login_password=raw_input("password:")
> if login_username in name and login_password in paword:
> print "login successful , proceed to page 2"
> break
> 
> else:
> print "login is unseccesful and please make sure your 
> username and password is correct"
> 
> 
> .l would like to do samething when we login a website. l want program if 
> username is not registered , register first , then store it , and l want 
> program ask for some specific characters , like 1,2,3../,%. 
> 
> thanks for any clearification in advance

for example : some websites ask for a password including some specific 
characters , like one letter, one ( /,%,*,),(,...) so my purpose is to create a 
program .first ask for username , then password , then check them , if they 
don't match with stored (username and password ) , make them register and 
during that , store "username " and "password" but "password must be including 
1 letter , 1 sign , and less than 10 length , more than 4 . l don't know how to 
do it.as l tried many things but  l got error . l hope it would be more 
explaintory as my English is not good enough.thanks for any advice in advance

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


Re: Regarding installation of python-3.5.1

2016-03-06 Thread Steven D'Aprano
On Sun, 6 Mar 2016 05:35 pm, Roshan S Sontakke wrote:

> Gud afternoon sir my self Roshan sontakke I have down loaded a setup of
> python-3.5.1 but nt able to install it gives an error message


Shall we guess what the error message says, or would you like to tell us?


-- 
Steven

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


Re: Python 3.5.1 (32-bit)_20160306131105

2016-03-06 Thread Steven D'Aprano
On Sun, 6 Mar 2016 04:32 pm, 程仿 wrote:

> when I am installing Python 3.5.1 (32-bit),some problems occurred.I hope
> you could offer me some help.This file may contain some information about
> the error.

What file?

Please COPY AND PASTE the text of the error message into your email.

-- 
Steven

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


Re: Reason for not allowing import twice but allowing reload()

2016-03-06 Thread Steven D'Aprano
On Sun, 6 Mar 2016 07:20 pm, alien2u...@gmail.com wrote:

> Based on the input from members, and my subsequent reading the
> textbook/tutorials, let me summarize my understanding of "why subsequent
> imports of same module are designed to be effect-less".

That is not correct. Imports are not a no-op, they always have an effect.
The effect is that they bind the module to a name in the current namespace.

What import does NOT do is *reload the module* from disk. But that's not the
same thing as being "effect-less".


> 1. Imports are costly affair, as it involves
>  - finding the module's file
>  - compile it to byte code (if needed)
>  - run the module's code to build the objects it defines.

Correct.


> 2a. Quoting from "Learning Python: Mark Lutz" : In Python, cross-file
> module linking
> is not resolved until such import statements are **executed at
> runtime**.

I don't understand that statement.


> import being a statement, can come anywhere a statement can, so a module
> can be selectively imported depending upon the conditions at runtime.

Correct.


> 2b. Inter-dependencies between modules: For example, A (main module)
> imports B, C, D
> and E. B again imports C and E, D imports B and C.
> 
> If import statements are processed entirely from scratch each time, it
> would amount to lot of **redundant (and costly)** work.
> 
> Secondly there could be dangerous? side-effects of reprocessing imports
> from scratch.

Correct.


> Let us say, in above example, module B does some initialization of
> variables, or things like resetting a file for further work during the
> session. These variables and file are updated during the course of
> execution of A.
> 
> Much later via some conditional path, module B is imported again, and BOOM
> (were import processed from scratch again).

Correct. This would be a bad thing.


> In this case - we are respecting that every import of a module should give
> same picture (assuming it is not modified across two different invocation
> during the program execution).
> 
> An argument here could be: to code module B in such a way that those
> initializations don't happen again, but just once - check before resetting
> etc. during the import.

How would you do that? How could a .py file know if it has already been
loaded?



-- 
Steven

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


Re: password and username code

2016-03-06 Thread John Gordon
In <1ed89545-f102-4538-bfe2-9d0e3dac8...@googlegroups.com> 
=?UTF-8?B?w5ZtZXIgc2FyxLE=?=  writes:

> l want program if username is not registered, register first,
> then store it, and l want program ask for some specific characters,
> like 1,2,3../,%. 

What is your process for finding out if a name is registered?  There
are lots of possible ways to do it.  Do you have one in mind?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Pyhon 2.x or 3.x, which is faster?

2016-03-06 Thread Steven D'Aprano
On Sun, 6 Mar 2016 10:34 pm, Tony van der Hoff wrote:

> Hi, I've been experimenting with a short test program under python 2.7
> and python 3.4.2. It's a simple read from file, and locate a word therein.
> 
> I get the (subjective) impression that python2  is slightly faster than
> python3. Is that correct? Is there any documentation to support this?

I believe that, overall, Python 3 is still slightly slower than Python 2,
but it's a near thing. Have a look at the latest performance benchmarks:

https://speed.python.org/comparison/

Eyeballing the graph, I estimate that the latest 3.x version is probably
about 10% slower overall, although different benchmarks show different
speeds.



-- 
Steven

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


Regarding installation of python-3.5.1

2016-03-06 Thread Roshan S Sontakke
Gud afternoon sir my self Roshan sontakke I have down loaded a setup of 
python-3.5.1 but nt able to install it gives an error message 
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.5.1 (32-bit)_20160306131105

2016-03-06 Thread ????
when I am installing Python 3.5.1 (32-bit)??some problems occurred.I hope you 
could offer me some help.This file may contain some information about the error.
-- 
https://mail.python.org/mailman/listinfo/python-list


???

2016-03-06 Thread kyleolson1988
I cant figure out how to get to the program so I can write code. started and 
introductory programming class for college and im unable to figure out how to 
open this program on my computer. please help if you can, your time would be 
much appreciate.






Sent from Windows Mail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Photon mass (was: [Still off-top] Physics)

2016-03-06 Thread Gene Heskett
On Saturday 05 March 2016 10:46:04 Thomas 'PointedEars' Lahn wrote:

> Gene Heskett wrote:
> > I've never heard of a massless photon,
>
> That is unfortunate as it should be common knowledge by now.
>
> > and they do exert a push on the surface they are reflected from, […]
>
> Photons exert a force on surfaces because they carry *momentum* or, as
> it had been understood in terminology that is obsolete now, a non-zero
> “*relativistic* mass” (that had been distinguished from “rest mass”).
>
To have "momentum" imply's mass in the real, we can measure it world.

However with my lack of education, I have a hard time reconciling that 
they travel at C speed, when the classical math says that anything with 
mass traveling at C speed will have aborbed enough energy in getting to 
C speed, that its mass is then infinite. But its obviously not.

I once used relativity to explain to a degree'd FCC engineer exactly why 
a UHF transmitter that used klystrons for amnplifiers, alway had a 
backgound audio buzz. At the moment this was taking place, the station  
was crippled as we'd had a circuit breaker failure, single phasing and 
stopping the cooling water pump, which in turn destroyed the klystron 
used as a visual amplifier (one circuit breaker boom as the building 
went dark when the tube filled with steam, byby $120,000 USD), so just 
to stay on the air, I had moved a weak & about used up klystron from the 
aural cabinet to the visual cabinet, and tee connected the aural drive 
into the visual drive.

When the engineer came in the door, one of the first things he had 
noticed when he monitored the station from about 15 miles away the 
previous evening, was that we were a UHF, but didn't have that annoying 
background buzz in the sound.  So I had to explain it.

What we were observing was that by combining the two carrier signals into 
one tube, meant that both signals were being treated equally to the  
phenomenon they had called incidental carrier phase modulation, and its 
created in the amplitude modulated signal because the 4 foot long 
electron beam is traveling at a speed where speed vs mass is beginning 
to make itself measureable. Said simply, the tube amplifies the signal 
by nominally 30db, by introducing an electrical field across the input 
cavities gap that alternately speeds up, or slows down, an electron 
traverseing that gap with a 20 kilovolt induced speed. 4 feet and  3 
more cavities later, those electrons are now bunched up, the ones in 
front slowing to fall into the bunch, and the ones behind being pushed 
to catch up with the bunch. That induces, because the beam is something 
north of 5 amps, a considerable amount of power in the last cavity which 
can be coupled back out and sent to the antenna, typically about 30 kw.

However, because this beam of electrons is traveling fast enough for 
relativity to come into play, the energy applied to speed the beam up 
encounters an electron with higher mass as it accelerates, whereas the 
energy applied to slow it encounters an electron with lower mass, so the 
deceleration is fractionally greater.  IOW, its not perfectly 
symetrical, the net effect being that the average speed of the beam is 
instantaneous power level dependent, the tube being effectively, 
physically longer, with a longer transit time as the power level rises.
This is efffectively a frequency modulation, and an unwanted effect.

Some circuits, once the cause of the phenom was known, were designed to 
predistort this by intruducing an opposing FM and cancel it, but by then 
the heyday of the klysron amplifier was coming to an end because of its 
horrible efficiency, that 30 kw of output came at a cost of a few hairs 
over 100kw in the beam supply, making a UHF transmitter the local power 
companies largest customer by a fairly wide margin. That tramsitter used 
nearly 200 kw for every hour it was on the air, and multi-thousand 
dollar power bills were getting the bean counters attention.

But when both signals, visual and aural, are subjected to the same 
effect, AND the sound detection is based on the FM of the 4.5 megahertz 
difference, it cancels out in the receiver. Later, while still operating 
crippled, I made some aural signal to noise measurements, finding truely 
amazing figures of nearly 80 db with video still applied, where when 
operating with 2 klystrons as intended, it was hard put to make a bit 
over 50 db.  It was such a problem that the FCC allowed us to make those 
measurements with the baseband video cable unplugged when doing a proof 
of performance, required for license renewal every 5 years back in those 
days.

So in that scenario, I have first hand knowledge about relativity despite 
my offical 8th grade education. Photons not having a mass but can exert 
a push isn't something this 81 yo wet ram can quite figure out.  In my 
mind, when the ball bounces, its mass exerts a push on the wall it was 
bounced off of.  For a photon to do that, requires it have a m

Phyton

2016-03-06 Thread Diego ...
Hello! I have a question in an exercise that says : Write an expression to 
determine whether a person should or should not pay tax . Consider paying tax 
people whose salary is greater than R $ 1,200.00

I do not know how to mount the logical expression !!!

It's like:

salary = 1250
tax = Not True
salary > 1200 or not tax 

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


even faster heaps

2016-03-06 Thread Sven R. Kunze

Hi python-list, hi Srinivas,

I managed to implement the mark&sweep approach for fast removal from 
heaps. This way, I got three pleasant results:


1) a substantial speed up!
2) an improved testsuite
3) discovery and fixing of several bugs

@Srinivas I would be honored if you could have a look at the 
implementation: https://github.com/srkunze/xheap . After all, it was 
your idea. I only perform the sweeping step during pop and remove with 
the condition of yours. :)


Using the original xheap benchmark 
, I could 
see huge speedups: from 50x/25x down to 3x/2x compared to heapq. That's 
a massive improvement. I will publish an update soon.


Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pyhon 2.x or 3.x, which is faster?

2016-03-06 Thread Peter Otten
Tony van der Hoff wrote:

> Hi, I've been experimenting with a short test program under python 2.7
> and python 3.4.2. 

Ideally you would provide the source.

> It's a simple read from file, and locate a word therein.

Do both runs operate on the same kind of string (either bytestring or 
unicode)?

> I get the (subjective) impression that python2  is slightly faster than
> python3. Is that correct? Is there any documentation to support this?
> 
> Thanks,


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


IDLE question: "you may still have to reload nested modules."

2016-03-06 Thread alien2utoo
Hello list,

I am following "Learning Python: Mark Lutz" and came across following in 
chapter 3
few days back.

[quote]
* You may still have to reload nested modules. Technically speaking, IDLE's
  Run->Run Module menu option always runs the current version of the top-level 
file
  only; imported files may still need to be interactively reloaded when 
changed. ...
[/quote]

It is slightly confusing, as to what it does imply. Could any IDLE guru clarify 
if I am missing or overlooking something?

If a needed-by-top-level-file module was changed after 'Run->Run Module', it 
would any
way need to be reloaded.

If it was changed between two "Run->Run Module" actions, won't it be 
automatically loaded afresh as a part of restarting Python interpreter and 
executing top-level-file [where is the question of reloading then?]?

[Side observation: though F5 or "Run->Run Module" restarts Python interpreter 
with top-level-file afresh [indicated by dir() content before and after], the 
command history is not reset during this. This likely confirms the GUI process 
being separate than interpreter.]

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


Re: Pyhon 2.x or 3.x, which is faster?

2016-03-06 Thread Terry Reedy

On 3/6/2016 6:34 AM, Tony van der Hoff wrote:

Hi, I've been experimenting with a short test program under python 2.7
and python 3.4.2. It's a simple read from file, and locate a word therein.

I get the (subjective) impression that python2  is slightly faster than
python3. Is that correct? Is there any documentation to support this?


The relative speed depends on the particular operation, the compiler and 
OS, and the particular 3.x.y version.  Since 3.3.0, string (unicode) 
operations have been sped up, sometimes by a lot.  If you are looking 
for string speed, get 3.4.4 or 3.5.1.


--
Terry Jan Reedy

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


Re: Application console for Tkinter program?

2016-03-06 Thread Terry Reedy

On 3/6/2016 4:23 AM, Christian Gollwitzer wrote:

Am 05.03.16 um 22:16 schrieb Terry Reedy:

Not now. A console is a REPL + text display to read from and print to.
The actual IDLE REPL is PyShell.ModifiedInterpreter, which subclasses
stdlib code.InteractiveInterpreter.  Most of the additions are for
interacting with the subprocess that runs user code.  You should start
instead with the base class.

The Shell text display is a subclass of a subclass of a class that
contains a subclass of Toplevel with the complete IDLE Menu and a Text
widget wrapper.  Again, this is too much baggage for an application
console.

The idlelib ColorDelegator syntax highlighter can be reused with a Text
instance.  See turtledemo.__main__ for an example.  I don't know if (or
how) IDLE's autocompletion modules could be reused in their current
state.  I believe Shell's history 'list' consists of the statements in
the Text instance prefixed by the '>>> ' prompt.


Thanks! I'll try to browse my way through the source code, these details
help a lot. I still haven't understood the difference between exec() and
eval(). I understand that for statements you want to exec them, for
expressions you eval it and print the result. When the user has entered
code, how does the REPL know if it should be eval'ed or exec'ed? I
assume that you don't try to parse the Python code manually to find this
out? Or you try to eval(), and if it doesn't compile, you exec()?


Python expressions are also statements.  Python REPLs exec statements. 
But to make Read-Exec-Print work like traditional Read-Eval-Print, 
Python, in interactive mode, echos the value of expression statements 
(and assign it to _ for later reuse).  So '2 + 2' echos 4 in REPL, or at 
least in the console and IDLE, '2 + 2' is useless in a program run in 
batch mode.


--
Terry Jan Reedy

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


Pyhon 2.x or 3.x, which is faster?

2016-03-06 Thread Tony van der Hoff
Hi, I've been experimenting with a short test program under python 2.7 
and python 3.4.2. It's a simple read from file, and locate a word therein.


I get the (subjective) impression that python2  is slightly faster than 
python3. Is that correct? Is there any documentation to support this?


Thanks,
--
Tony van der Hoff| mailto:t...@vanderhoff.org
Buckinghamshire, England |
--
https://mail.python.org/mailman/listinfo/python-list


Re: Compact connected regular graphs

2016-03-06 Thread Mark Lawrence

On 06/03/2016 11:04, jonas.thornv...@gmail.com wrote:

Den söndag 6 mars 2016 kl. 12:01:02 UTC+1 skrev Mark Lawrence:

On 06/03/2016 10:39, jonas.thornv...@gmail.com wrote:

How come all graphs using 42 links and more then 84 nodes have compact  regular 
connected solutions?

Did turn off animation for more than a couple of thousands of  links so the 
animation is off when searching but script give message and numerical results 
on search.

http://jt.node365.se/nodes15.html

Do anyone know?


http://jt.node365.se/Compact.rtf



Where is the Python question here?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


It is the Python that squeeze the information out of the graphs.



I'll try again, where is the Python question here?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Compact connected regular graphs

2016-03-06 Thread jonas . thornvall
Den söndag 6 mars 2016 kl. 12:01:02 UTC+1 skrev Mark Lawrence:
> On 06/03/2016 10:39, jonas.thornv...@gmail.com wrote:
> > How come all graphs using 42 links and more then 84 nodes have compact  
> > regular connected solutions?
> >
> > Did turn off animation for more than a couple of thousands of  links so the 
> > animation is off when searching but script give message and numerical 
> > results on search.
> >
> > http://jt.node365.se/nodes15.html
> >
> > Do anyone know?
> >
> >
> > http://jt.node365.se/Compact.rtf
> >
> 
> Where is the Python question here?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

It is the Python that squeeze the information out of the graphs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compact connected regular graphs

2016-03-06 Thread Mark Lawrence

On 06/03/2016 10:39, jonas.thornv...@gmail.com wrote:

How come all graphs using 42 links and more then 84 nodes have compact  regular 
connected solutions?

Did turn off animation for more than a couple of thousands of  links so the 
animation is off when searching but script give message and numerical results 
on search.

http://jt.node365.se/nodes15.html

Do anyone know?


http://jt.node365.se/Compact.rtf



Where is the Python question here?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Compact connected regular graphs

2016-03-06 Thread jonas . thornvall
How come all graphs using 42 links and more then 84 nodes have compact  regular 
connected solutions?

Did turn off animation for more than a couple of thousands of  links so the 
animation is off when searching but script give message and numerical results 
on search.

http://jt.node365.se/nodes15.html

Do anyone know?


http://jt.node365.se/Compact.rtf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Application console for Tkinter program?

2016-03-06 Thread Christian Gollwitzer

Am 05.03.16 um 22:16 schrieb Terry Reedy:

Not now. A console is a REPL + text display to read from and print to.
The actual IDLE REPL is PyShell.ModifiedInterpreter, which subclasses
stdlib code.InteractiveInterpreter.  Most of the additions are for
interacting with the subprocess that runs user code.  You should start
instead with the base class.

The Shell text display is a subclass of a subclass of a class that
contains a subclass of Toplevel with the complete IDLE Menu and a Text
widget wrapper.  Again, this is too much baggage for an application
console.

The idlelib ColorDelegator syntax highlighter can be reused with a Text
instance.  See turtledemo.__main__ for an example.  I don't know if (or
how) IDLE's autocompletion modules could be reused in their current
state.  I believe Shell's history 'list' consists of the statements in
the Text instance prefixed by the '>>> ' prompt.


Thanks! I'll try to browse my way through the source code, these details 
help a lot. I still haven't understood the difference between exec() and 
eval(). I understand that for statements you want to exec them, for 
expressions you eval it and print the result. When the user has entered 
code, how does the REPL know if it should be eval'ed or exec'ed? I 
assume that you don't try to parse the Python code manually to find this 
out? Or you try to eval(), and if it doesn't compile, you exec()?


Christian

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


Re: Adding Icon To Tkinter Window - Followup

2016-03-06 Thread Christian Gollwitzer

Am 06.03.16 um 06:53 schrieb Wildman:

On Sat, 05 Mar 2016 19:36:19 +0100, Christian Gollwitzer wrote:

import Tkinter
from Tkinter import Tk
root = Tk()
img = Tkinter.Image("photo", file="appicon.gif")
root.call('wm','iconphoto',root._w,img)


The above worked perfectly.  Thank you very much.


Then you should try if it works also with the last line replaced as

root.wm_iconphoto(True, img)

(as Serhiy and Terry wrote). My system python which I used to test this 
was just too old to wrap iconphoto, yours should be up to date.


Christian



According to "root.eval('info patchlevel')" I have version 8.6.2.
PNG worked.  That is good because PNG is a common file type for
Linux icons.


PS: 8.6.2 is from mid 2014, that's OK - though we've had a brand new 
release (8.6.5) in February 2016

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


Re: Reason for not allowing import twice but allowing reload()

2016-03-06 Thread alien2utoo
>From the discussions in this thread, I get the impression that there are 
>genuine
requirements to reload() a module during a program's execution.

It is fairly easy to see reload() in context of interactive execution, but how 
does it
come into picture in case of non-interactive Python program executions?

- one way could to be periodically poll for change of module version (time 
stamp etc.),
  and reload(),
- other could be sending a signal to program and reload() selected modules 
during
  processing of that signal by the program. Is it done this way in Python as 
well?

  There used to be programs which could reload the configuration file (and act
  accordingly) without needing to restart the program) when specific signal was 
sent
  to them.

Am I on right track in my understanding?
What are the other ways to accomplish reload() during the execution of a 
non-interactive Python program?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reason for not allowing import twice but allowing reload()

2016-03-06 Thread alien2utoo
Based on the input from members, and my subsequent reading the 
textbook/tutorials, let
me summarize my understanding of "why subsequent imports of same module are 
designed to be effect-less".

1. Imports are costly affair, as it involves
 - finding the module's file
 - compile it to byte code (if needed)
 - run the module's code to build the objects it defines.

2a. Quoting from "Learning Python: Mark Lutz" : In Python, cross-file module 
linking
is not resolved until such import statements are **executed at runtime**.

import being a statement, can come anywhere a statement can, so a module can be
selectively imported depending upon the conditions at runtime.

2b. Inter-dependencies between modules: For example, A (main module) imports B, 
C, D
and E. B again imports C and E, D imports B and C.

If import statements are processed entirely from scratch each time, it would 
amount
to lot of **redundant (and costly)** work.

Secondly there could be dangerous? side-effects of reprocessing imports from 
scratch.

Let us say, in above example, module B does some initialization of variables, or
things like resetting a file for further work during the session. These 
variables and
file are updated during the course of execution of A.

Much later via some conditional path, module B is imported again, and BOOM (were
import processed from scratch again).

In this case - we are respecting that every import of a module should give same
picture (assuming it is not modified across two different invocation during the
program execution).

An argument here could be: to code module B in such a way that those 
initializations
don't happen again, but just once - check before resetting etc. during the 
import.
But wouldn't that violate the *same picture* requirement?

Probably my example is not that perfect.
-- 
https://mail.python.org/mailman/listinfo/python-list