Re: iterating over a file with two pointers

2013-09-19 Thread Joshua Landau
Although "tee" is most certainly preferable because IO is far slower
than the small amounts of memory "tee" will use, you do have this
option:

def iterate_file_lines(file):
"""
Iterate over lines in a file, unlike normal
iteration this allows seeking.
"""
while True:
line = thefile.readline()
if not line:
break

yield line


thefile = open("/tmp/thefile")
thelines = iterate_file_lines(thefile)

for line in thelines:
print("Outer:", repr(line))

if is_start(line):
outer_position = thefile.tell()

for line in thelines:
print("Inner:", repr(line))

if is_end(line):
break

thefile.seek(outer_position)

It's simpler than having two files but probably not faster, "tee" will
almost definitely be way better a choice (unless the subsections can't
fit in memory) and it forfeits being able to change up the order of
these things.

If you want to change up the order to another defined order, you can
think about storing the subsections, but if you want to support
independent iteration you'll need to seek before every "readline"
which is a bit silly.

Basically, read it all into memory like Steven D'Aprano suggested. If
you really don't want to, use "tee". If you can't handle non-constant
memory usage (really? You're reading lines, man) I'd suggest my
method. If you can't handle the inflexibility there, use multiple
files.

There, is that enough choices?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: iterating over a file with two pointers

2013-09-19 Thread Peter Otten
Roy Smith wrote:

>> Dave Angel  wrote (and I agreed with):
>>> I'd suggest you open the file twice, and get two file objects.  Then you
>>> can iterate over them independently.
> 
> 
> On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote:
>> There's no need to use OS resources by opening the file twice or to
>> screw up the IO caching with seek().
> 
> There's no reason NOT to use OS resources.  That's what the OS is there
> for; to make life easier on application programmers.  Opening a file twice
> costs almost nothing.  File descriptors are almost as cheap as whitespace.
> 
>> Peter's version holds just as many lines as is necessary in an
>> internal Python buffer and performs the minimum possible
>> amount of IO.
> 
> I believe by "Peter's version", you're talking about:
> 
>> from itertools import islice, tee
>> 
>> with open("tmp.txt") as f:
>> while True:
>> for outer in f:
>> print outer,
>> if "*" in outer:
>> f, g = tee(f)
>> for inner in islice(g, 3):
>> print "   ", inner,
   del g # a good idea in the general case
>> break
>> else:
>> break
> 
> 
> There's this note from
> http://docs.python.org/2.7/library/itertools.html#itertools.tee:
> 
>> This itertool may require significant auxiliary storage (depending on how
>> much temporary data needs to be stored). In general, if one iterator uses
>> most or all of the data before another iterator starts, it is faster to
>> use list() instead of tee().
> 
> 
> I have no idea how that interacts with the pattern above where you call
> tee() serially.  

As I understand it the above says that

items = infinite()
a, b = tee(items)
for item in islice(a, 1000):
   pass
for pair in izip(a, b):
pass

stores 1000 items and can go on forever, but

items = infinite()
a, b = tee(items)
for item in a:
pass

will consume unbounded memory and that if items is finite using a list 
instead of tee is more efficient. The documentation says nothing about

items = infinite()
a, b = tee(items)
del a
for item in b:
   pass

so you have to trust Mr Hettinger or come up with a test case...

> You're basically doing
> 
> with open("my_file") as f:
> while True:
> f, g = tee(f)
> 
> Are all of those g's just hanging around, eating up memory, while waiting
> to be garbage collected?  I have no idea.  

I'd say you've just devised a nice test to find out ;)

> But I do know that no such
> problems exist with the two file descriptor versions.

The trade-offs are different. My version works with arbitrary iterators 
(think stdin), but will consume unbounded amounts of memory when the inner 
loop doesn't stop.

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


Re: linregress and polyfit

2013-09-19 Thread chitturk
tried (1,) - still same error ... 
printed "z" and looks right, len(z) OK 
(puzzling)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess call is not waiting.

2013-09-19 Thread harish.barve...@gmail.com
subprocess.call(tempFileName, shell=True).communicate()

this process is not blocking. I want to make a blocking call to it. please help
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: scipy 11 and scipy 12

2013-09-19 Thread Oscar Benjamin
On 19 September 2013 03:42, Steven D'Aprano
 wrote:
>> For Python 2.7 I think that easy_install will be able to install from
>> the sourceforge binaries, e.g
>>
>> easy_install --user scipy
>>
>> but I may be wrong.

I should add that I meant the above as a suggestion for a Windows user.

> If I recall correctly, and I may not, easy_install doesn't support per-
> user installs with the --user option.

It has the option:

$ easy_install --help | grep -- --user
  --user install in user site-package 'C:\Documents and

I just don't know if that works when easy_install works from a binary
rather than an sdist.


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


Re: iterating over a file with two pointers

2013-09-19 Thread Oscar Benjamin
On 19 September 2013 08:23, Peter Otten <__pete...@web.de> wrote:
> Roy Smith wrote:
>>
>> I believe by "Peter's version", you're talking about:
>>
>>> from itertools import islice, tee
>>>
>>> with open("tmp.txt") as f:
>>> while True:
>>> for outer in f:
>>> print outer,
>>> if "*" in outer:
>>> f, g = tee(f)
>>> for inner in islice(g, 3):
>>> print "   ", inner,
>del g # a good idea in the general case
>>> break
>>> else:
>>> break
>>
>> There's this note from
>> http://docs.python.org/2.7/library/itertools.html#itertools.tee:
>>
>>> This itertool may require significant auxiliary storage (depending on how
>>> much temporary data needs to be stored). In general, if one iterator uses
>>> most or all of the data before another iterator starts, it is faster to
>>> use list() instead of tee().

This is referring to the case where your two iterators get out of sync
by a long way. If you only consume 3 extra items it will just store
those 3 items in a list.

>> I have no idea how that interacts with the pattern above where you call
>> tee() serially.

Fair point.

>
> As I understand it the above says that
>
> items = infinite()
> a, b = tee(items)
> for item in islice(a, 1000):
>pass
> for pair in izip(a, b):
> pass
>
> stores 1000 items and can go on forever, but
>
> items = infinite()
> a, b = tee(items)
> for item in a:
> pass
>
> will consume unbounded memory and that if items is finite using a list
> instead of tee is more efficient. The documentation says nothing about
>
> items = infinite()
> a, b = tee(items)
> del a
> for item in b:
>pass
>
> so you have to trust Mr Hettinger or come up with a test case...
>
>> You're basically doing
>>
>> with open("my_file") as f:
>> while True:
>> f, g = tee(f)
>>
>> Are all of those g's just hanging around, eating up memory, while waiting
>> to be garbage collected?  I have no idea.
>
> I'd say you've just devised a nice test to find out ;)

$ cat tee.py
#!/usr/bin/env python

import sys
from itertools import tee

items = iter(range(int(sys.argv[1])))

while True:
for x in items:
items, discard = tee(items)
break
else:
break

print(x)

$ time py -3.3 ./tee.py 1


real1m47.711s
user0m0.015s
sys 0m0.000s

While running the above python.exe was using 6MB of memory (according
to Task Manager). I believe this is because tee() works as follows
(which I made up but it's how I imagine it).

When you call tee(iterator) it creates two _tee objects and one
_teelist object. The _teelist object stores all of the items that have
been seen by only one of _tee1 and _tee2, a reference to iterator and
a flag indicating which _tee object has seen more items. When say
_tee2 is deallocated the _teelist becomes singly owned and no longer
needs to ever accumulate items (so it doesn't). So the dereferenced
discard will not cause an arbitrary growth in memory usage.

There is a separate problem which is that if you call tee() multiple
times then you end up with a chain of tees and each next call would go
through each one of them. This would cause a linear growth in the time
taken to call next() leading to quadratic time performance overall.
However, this does not occur with the script I showed above. In
principle it's possible for a _tee object to realise that there is a
chain of singly owned _tee and _teelist objects and bypass them
calling next() on the original iterator but I don't know if this is
what happens.

However, when I ran the above script on Python 2.7 it did consume
massive amounts of memory (1.6GB) and ran slower so maybe this depends
on optimisations that were introduced in 3.x.

Here's an alternate iterator recipe that doesn't depend on these optimisations:

from itertools import islice
from collections import deque

class Peekable(object):

def __init__(self, iterable):
self.iterator = iter(iterable)
self.peeked = deque()

def __iter__(self):
while True:
while self.peeked:
yield self.peeked.popleft()
yield next(self.iterator)

def peek(self):
for p in self.peeked:
yield p
for val in self.iterator:
self.peeked.append(val)
yield val

with open("tmp.txt") as f:
f = Peekable(f)
for outer in f:
print outer,
if "*" in outer:
for inner in islice(f.peek(), 3):
print "   ", inner,


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


Re: linregress and polyfit

2013-09-19 Thread Oscar Benjamin
On 18 September 2013 20:57, Dave Angel  wrote:
> On 18/9/2013 09:38, chitt...@uah.edu wrote:
>
>> Thanks - that helps ... but it is puzzling because
>>
>> np.random.normal(0.0,1.0,1) returns exactly one
>> and when I checked the length of "z", I get 21 (as before) ...
>>
>>
>
> I don't use Numpy, so this is just a guess, plus reading one web page.
>
> According to:
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html
>
> the 3rd argument to normal should be a tuple.  So if you want a single
> element, you should have made it (1,)

Numpy accepts ints in place of shape tuples so this makes no difference.

> As for checking the 'length of "z"' did you just use the len() function?
> That just tells you the first dimension.  Have you tried simply printing
> out "z" ?

Exactly. What you need to check is the shape attribute (converting to
numpy array first if necessary):

>>> import numpy as np
>>> a = np.random.normal(0, 1, 1)
>>> a
array([-0.90292348])
>>> a.shape
(1,)
>>> a[0]
-0.90292348393433797
>>> np.array(a[0])
array(-0.902923483934338)
>>> np.array(a[0]).shape
()
>>> [a, a]
[array([-0.90292348]), array([-0.90292348])]
>>> np.array([a, a])
array([[-0.90292348],
   [-0.90292348]])
>>> np.array([a, a]).shape
(2, 1)
>>> np.random.normal(0, 1, 2).shape
(2,)

The square brackets in 'array([-0.90292348])' indicate that numpy
considers this to be a 1-dimensional array of length 1 rather than a
scalar value (which would have an empty shape tuple).


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


Re: iterating over a file with two pointers

2013-09-19 Thread Peter Otten
Oscar Benjamin wrote:

> $ cat tee.py
> #!/usr/bin/env python
> 
> import sys
> from itertools import tee
> 
> items = iter(range(int(sys.argv[1])))
> 
> while True:
> for x in items:
> items, discard = tee(items)
> break
> else:
> break
> 
> print(x)
> 
> $ time py -3.3 ./tee.py 1
> 
> 
> real1m47.711s
> user0m0.015s
> sys 0m0.000s
> 
> While running the above python.exe was using 6MB of memory (according
> to Task Manager). I believe this is because tee() works as follows
> (which I made up but it's how I imagine it).

[...]

> However, when I ran the above script on Python 2.7 it did consume
> massive amounts of memory (1.6GB) and ran slower so maybe this depends
> on optimisations that were introduced in 3.x.

Did you use xrange()?
 

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


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread random832
On Wed, Sep 18, 2013, at 16:13, Dave Angel wrote:
> So is the bug in Excel, in Windows, or in the Python library?  Somebody
> is falling down on the job;  if Windows defines the string as ending at
> the first null, then the Python interface should use that when defining
> the text defined with CF_UNICODETEXT.
> 
> Or maybe it's an example of ill-defined Windows specs.

I think it's a matter of ill-defined windows specs - the clipboard data
has an exact size, and in principle that size is always used, for
example, for numerous binary formats. But the text clipboard has often
been treated as a C string by a wide variety of different applications,
so one could argue that has become a de facto standard.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: iterating over a file with two pointers

2013-09-19 Thread Oscar Benjamin
On 19 September 2013 15:38, Peter Otten <__pete...@web.de> wrote:
>> While running the above python.exe was using 6MB of memory (according
>> to Task Manager). I believe this is because tee() works as follows
>> (which I made up but it's how I imagine it).
>
> [...]
>
>> However, when I ran the above script on Python 2.7 it did consume
>> massive amounts of memory (1.6GB) and ran slower so maybe this depends
>> on optimisations that were introduced in 3.x.
>
> Did you use xrange()?

No I didn't. :)

Okay so it only uses 4.6MB of memory and it runs at the same speed:
there's no problem with chaining tee objects as long as you discard
them. If you don't discard them then a script like the one I wrote
would quickly blow all the system memory.


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


A question about semantics from the standard library's documentation

2013-09-19 Thread Aseem Bansal
In Python 3.3.2 documentation on the Python Standard library's introduction 
these sentences are given

"For these types, the Python language core defines the form of literals and 
places some constraints on their semantics, but does not fully define the 
semantics. (On the other hand, the language core does define syntactic 
properties like the spelling and priorities of operators.)"

That got me confused. What is defined by the language and what is not? 
Can someone give me an example about what this means?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lxml question -- creating an etree.Element attribute with ':' in the name

2013-09-19 Thread Stefan Behnel
Burak Arslan, 18.09.2013 21:35:
> On 09/18/13 21:59, Roy Smith wrote:
>> I can create an Element with a 'foo' attribute by doing:
>>
>> etree.Element('my_node_name', foo="spam")
>>
>> But, how do I handle something like:
>>
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";, since "xmlns:xsi" 
>> isn't a valid python identifier?
> 
> xmlns: is a prefix with a special meaning: it defines an xml namespaces
> prefix. you should read about how they work.

Absolutely. For the specific case of a namespaced attribute, one way to do
it goes like this:

   el = etree.Element('my_node_name')
   el.set('{http://www.w3.org/2001/XMLSchema-instance}xsi', 'int')


> The following:
> 
> Element('{http://www.w3.org/2001/XMLSchema-instance}my_node_name')
> 
> will generate a proper xmlns declaration for you. It may not be the same
> every time, but it will do the job just as well.

For this specific namespace, and also a couple of other well-known
namespace URIs, lxml will use the "expected" prefix by default.

Stefan


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


django admin.py error

2013-09-19 Thread Gary Roach
Installation of the django admin.py package worked fine. But. when I 
tried to add my database to the admin page I get the following error:


ImportError at /admin/

cannot import name membership

Request Method: GET
Request URL:http://127.0.0.1:8000/admin/
Django Version: 1.5.2
Exception Type: ImportError
Exception Value:

cannot import name membership

Exception Location: 
/home/gary/ProgramFiles/mysite/mysite/admin.py  in
  , line 4
Python Executable:  /usr/bin/python
Python Version: 2.7.3
Python Path:

['/home/gary/ProgramFiles/mysite/mysite',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

My admin.py file is:
#Adding this app to the admin page.

from django.contrib import admin
	from mysite.models import membership, address, status, 	audio, video, 
photos


admin.site.register(membership)
admin.site.register(address)
admin.site.register(status)
admin.site.register(audio)
admin.site.register(video)
admin.site.register(photos)

I can't seem to locate the source of the problem. Everything seems to be 
installed properly.


Any help will be sincerely appreciated.

Gary R




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


Re: django admin.py error

2013-09-19 Thread John Gordon
In  Gary Roach 
 writes:

> Installation of the django admin.py package worked fine. But. when I 
> tried to add my database to the admin page I get the following error:

>   ImportError at /admin/

>   cannot import name membership

>   ['/home/gary/ProgramFiles/mysite/mysite',

> My admin.py file is:
>   #Adding this app to the admin page.

>   from django.contrib import admin
>   from mysite.models import membership, address, status,  audio, video, 
> photos

Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object
named 'membership'?

-- 
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


Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread William Bryant
the word 'def' has  squiggily lines but the program works fine. It says: Syntax 
Error: expected an indented block. - why?

def restart():
print("""



Cacluation DONE!



""")
restart = input("\nEnter yes if you want to make a new list and no if you 
want to close the program (yes/no):  ")
restart
if restart == "yes" or restart == "y" or restart == "new list":
print("You want make a new list...\n")
time.sleep(1)
NOS()
elif restart == "no" or restart == "n" or restart == "close":
print("Goodbye!")
time.sleep(1)
print("Goodbye!")
time.sleep(1)
print("Goodbye!")
time.sleep(1)
print("Goodbye!")
time.sleep(1)
print("Goodbye!")
time.sleep(1)
quit()
else:
print("type y or n")
time.sleep(0.5)
restart()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread patrick vrijlandt
John Gordon  wrote:
> In <22b99b0a-598f-4500-9de9-5041c2ce2...@googlegroups.com> William Bryant
>  writes:
> 
>> the word 'def' has  squiggily lines but the program works fine. It says:
>> Syntax Error: expected an indented block. - why?
> 
>> def restart():
> 
> This may be caused by the code before 'def'.  Post the whole program.

It may also have to do with having both tabs and spaces in one source file.
Python cannot recognise the indentation if you do that. Replace al tabs by
4 spaces.

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


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread Ian Kelly
Syntactically, it looks fine.  I would guess the problem is with
whatever editor you are using.  Or as John noted, it could be caused
by the code above it.

I do see an unrelated bug in there, though.  You are using the name
"restart" both for a string entered by the user and for the name of
the function, which is called recursively.  The name for the string,
which is local, shadows the name for the function, which is global.
So if the program ever hits the third branch of the if statement you
will get an error.

Python doesn't optimize tail-recursion, so you would get a different
error if the user hit that branch enough times (around 1000)
consecutively, as the interpreter hits the stack limit.  For example,
if they just held down the Enter key for a while.  So this looping
would be better accomplished with a while True loop and break
statements than with recursion.

On Thu, Sep 19, 2013 at 12:46 PM, William Bryant  wrote:
> the word 'def' has  squiggily lines but the program works fine. It says: 
> Syntax Error: expected an indented block. - why?
>
> def restart():
> print("""
>
> 
>
> Cacluation DONE!
>
> 
>
> """)
> restart = input("\nEnter yes if you want to make a new list and no if you 
> want to close the program (yes/no):  ")
> restart
> if restart == "yes" or restart == "y" or restart == "new list":
> print("You want make a new list...\n")
> time.sleep(1)
> NOS()
> elif restart == "no" or restart == "n" or restart == "close":
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> quit()
> else:
> print("type y or n")
> time.sleep(0.5)
> restart()
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: django admin.py error (solved)

2013-09-19 Thread Gary Roach

On 09/19/2013 11:56 AM, John Gordon wrote:

In  Gary Roach 
 writes:


On 09/19/2013 11:15 AM, John Gordon wrote:

Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object
named 'membership'?

Yes. The following is the top part of the models.py file: q
 class Membership(models.Model):
  id_membership = models.IntegerField(unique=True, primary_key=True)

I see something named 'Membership', but nothing named 'membership'.
Python names are case-sensitive.

Stupid stupid stupid. Thanks. You would think that after working with 
Linux for over 10 years that I wouldn't pull such a stunt. Thanks. 
Everything now working fine.


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


Re: A question about semantics from the standard library's documentation

2013-09-19 Thread Chris Angelico
On Fri, Sep 20, 2013 at 1:28 AM, Aseem Bansal  wrote:
> In Python 3.3.2 documentation on the Python Standard library's introduction 
> these sentences are given
>
> "For these types, the Python language core defines the form of literals and 
> places some constraints on their semantics, but does not fully define the 
> semantics. (On the other hand, the language core does define syntactic 
> properties like the spelling and priorities of operators.)"

In future, a link would help :)

http://docs.python.org/3/library/intro.html

> That got me confused. What is defined by the language and what is not?
> Can someone give me an example about what this means?

The core language MUST be implemented in the "outer language" (C for
CPython, Java for Jython... PyPy makes this a bit confusing, but
there's still the same distinction). You can't write Python code to
determine how to parse Python code. However, this core is actually
quite small. It consists of everything necessary to actually parse
your script (so, the indentation and tokenization rules, etc), plus
enough classes to be able to handle literals (there needs to be a str
to handle "Hello, world", for instance). Once the core is built, the
rest of the language can be implemented in Python. That's the standard
library.

Quite a bit of CPython's stdlib is actually implemented in C, for
performance; but huge slabs of it aren't, they're just Python code on
par with the scripts you write yourself. They're part of the language
ecosystem - if you claim you "know Python", you have to know at least
something about the stdlib - but it's much more easily tinkered with,
since you can just drop in a replacement bit of Python.

Take the hex() built-in function as an example. I can replace it[1] by
simply creating my own function with the same name:

>>> def hex(x):
return x+curse(x)-sanity()

It's not hard to roll your own hex() if you want to (base conversion
is easy enough). So hex() needn't be part of the core language, but
can simply be provided by a bit of Python code that gets imported
automatically.

In contrast, the 'def' statement MUST be provided by the core
language. You can't create a function that gives you the ability to
create functions! You also can't create the + operator, although it's
conceivable to have a language that grants user-level code that power;
in Python, at least, all operators are language features. However, the
exact behaviour of that + operator can be customized in Python, using
magic methods. That's the main difference between the core language
and the standard library - the stdlib could be, even if it isn't,
implemented in the language itself.

ChrisA

[1] This example just shadows the name, but near enough. Fiddling with
__builtins__ is a better "replacement", but it comes to the same
thing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread Neil Cerutti
On 2013-09-18, Dave Angel  wrote:
> On 18/9/2013 17:40, Neil Hodgson wrote:
>
>> Dave Angel:
>>
>>> So is the bug in Excel, in Windows, or in the Python library?  Somebody
>>> is falling down on the job;  if Windows defines the string as ending at
>>> the first null, then the Python interface should use that when defining
>>> the text defined with CF_UNICODETEXT.
>>
>> Everything is performing correctly. win32clipboard is low-level 
>> direct access to the Win32 clipboard API. A higher level API which is 
>> more easily used from Python could be defined on top of this if anyone 
>> was motivated.
>>
>> Neil
>
> Clearly you miss the point.  If the clipboard API is defined to
> return a null-terminated string, then the problem is in the
> Python library which doesn't do a strlen() (or the
> wide-character equivalent;  I forget its name) on the results.

Python can't really know if you're pasting text or a screenshot
or what.

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


Re: django admin.py error

2013-09-19 Thread Gary Roach

On 09/19/2013 11:15 AM, John Gordon wrote:

In  Gary Roach 
 writes:


Installation of the django admin.py package worked fine. But. when I
tried to add my database to the admin page I get the following error:

ImportError at /admin/



Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object
named 'membership'?


Yes. The following is the top part of the models.py file: q

   from __future__ import unicode_literals

   from django.db import models

   class Membership(models.Model):
id_membership = models.IntegerField(unique=True, primary_key=True)
first_name = models.CharField(max_length=20L, blank=True)
middle_name = models.CharField(max_length=20L, blank=True)
last_name = models.CharField(max_length=20L, blank=True)
born = models.DateField(null=True, blank=True)
born_date_accuracy = models.CharField(max_length=8L, blank=True)
died = models.DateField(null=True, blank=True)
died_date_accuracy = models.CharField(max_length=8L, blank=True)
photo_url = models.CharField(max_length=200L,
   db_column='photo_URL', blank=True) # Field name made lowercase.
class Meta:
db_table = 'membership'

   class Address(models.Model):
id_address = models.IntegerField(unique=True, primary_key=True)
street = models.CharField(max_length=45L, blank=True)
city = models.CharField(max_length=45L, blank=True)
state = models.CharField(max_length=45L, blank=True)
class Meta:
db_table = 'address'

   class AddressHasMembership(models.Model):
address_id_address = models.ForeignKey(Address,
   db_column='address_id_address')
membership_id_membership = models.ForeignKey('Membership',
   db_column='membership_id_member
   ship')
class Meta:
db_table = 'address_has_membership'

I hope this helps. Thanks for the reply

Gary R







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


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread John Gordon
In <22b99b0a-598f-4500-9de9-5041c2ce2...@googlegroups.com> William Bryant 
 writes:

> the word 'def' has  squiggily lines but the program works fine. It says:
> Syntax Error: expected an indented block. - why?

> def restart():

This may be caused by the code before 'def'.  Post the whole program.

-- 
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: A question about semantics from the standard library's documentation

2013-09-19 Thread Terry Reedy

On 9/19/2013 11:28 AM, Aseem Bansal wrote:

In Python 3.3.2 documentation on the Python Standard library's introduction 
these sentences are given

"For these types, the Python language core defines the form of literals and places 
some constraints on their semantics, but does not fully define the semantics. (On the 
other hand, the language core does define syntactic properties like the spelling and 
priorities of operators.)"


The two preceeding sentences are
"The “Python library” contains several different kinds of components.

It contains data types that would normally be considered part of the 
“core” of a language, such as numbers and lists."



That got me confused. What is defined by the language and what is not?
Can someone give me an example about what this means?


Take ints. The language manual specific the form of int literals. It 
specifies the operations in general terms of 'integers'. It specifies 
the precedence of the operators. It does not actually specify the 
meaning (semantics) of m + n. You are safe in assuming that (int)2 + 
(int)2 = (int)4. However type(2**31) is different on 2.7- 32-bit builds 
(long) and 3.0+ (always int). Also note that the language reference does 
not specify the int methods other than the special methods needed to 
implement the operators.


--
Terry Jan Reedy


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


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread Dave Angel
On 19/9/2013 14:46, William Bryant wrote:

> the word 'def' has  squiggily lines but the program works fine. It says: 
> Syntax Error: expected an indented block. - why?
>

The direct answer is that your terminal program must be broken.  it
should not use "squiggly lines" for any purposes.

But perhaps you're not seeing this in terminal, but in some text editor.
Better specify what that is.

As for the "Syntax Error..."   Better supply the entire traceback.  I
can't see how you consider that error message as "working."

> def restart():

Better give it a different name, since you're using this same name as a
local within the function.

> print("""
>
> 
>
> Cacluation DONE!
>
> 
>
> """)
> restart = input("\nEnter yes if you want to make a new list and no if you 
> want to close the program (yes/no):  ")
> restart

This line does nothing, as has been pointed out before in other
messages. of yours.  You're not printing it, assigning it to something,
calling it, or whatever.

> if restart == "yes" or restart == "y" or restart == "new list":
> print("You want make a new list...\n")
> time.sleep(1)
> NOS()

There's no such function.

> elif restart == "no" or restart == "n" or restart == "close":
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> print("Goodbye!")
> time.sleep(1)
> quit()

No such function.

> else:
> print("type y or n")
> time.sleep(0.5)
> restart()

You're using recursion when a simple loop is called for.

-- 
DaveA


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


Re: Is %z broken for return values of time.gmtime()?

2013-09-19 Thread Anssi Saari
random...@fastmail.us writes:

> I would argue that it _should_ be, and that it should populate it with 0
> in gmtime or either with timezone/altzone or by some sort of reverse
> calculation in localtime, but it is not. Another problem to add to my
> list of reasons for my recent python-ideas proposal.

Docs say that tm_gmtoff and tm_zone are available if the struct tm in
the underlying C library has it. Based on that I kinda expected Cygwin
to have it but apparently not.
-- 
https://mail.python.org/mailman/listinfo/python-list


Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread cython
Hello All,

I really hate Windows, and I have only intermittent access to Windows machines 
right now.

When I install Python 2.7 on Windows using the MSI installer, it definitely 
does not modify the PATH variable. So I modify the PATH variable myself as 
follows:

setx PATH %PATH%;C:\Python27\

Question 1: The command above requires a reboot in order to take effect, at 
least on Windows 8. How do I make it take effect immediately? Maybe if I repeat 
the same command again with 'set' instead of 'setx'? Does 'set' affect the 
whole machine, or only the current CMD.EXE session?

Question 2: python-guide.org suggests adding C:\Python27\Scripts\ to the PATH 
as well. When is that necessary or helpful? If I forget to do that and have 
problems later, how can I tell the cause of the problems?

Question 3: Does the Windows MSI installer from Python.org include Setuptools? 
python-guide.org implies that it does not include Setuptools, but I have never 
needed to manually install Setuptools, I am always able to use easy_install 
right away. Is my memory warped, or perhaps tainted by old Python installs on 
the same machine?

Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the 
best way to install it from the command line in a future-proof manner (on 
Windows)? I am imagining something like this:

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py

However, (1) wget is not a Windows command. What is the Windows command? And 
(2) is that URL the best possible URL? Or will that URL only download an old 
version, and there is a better URL for new versions?

Thank you,

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


Re: Bug tracker breaks when given a username with an uppercase letter

2013-09-19 Thread Terry Reedy

On 9/19/2013 12:33 PM, random...@fastmail.us wrote:

Registration appears to succeed, but does not allow login, and I can't
tell if email confirmation worked or not. I was able to register by
changing it to lowercase, but I had to guess what was happening.


Odd. There are existing usernames with uppercase.


--
Terry Jan Reedy

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


Re: Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread cython
On Thursday, September 19, 2013 4:06:56 PM UTC-4, Skip Montanaro wrote:
>
> I am not a Windows person, but wouldn't pip do the trick?
> 

PIP would definitely do the trick. Does the MSI include PIP? If it does not 
include PIP, then how can I easily install it from the command line? I am 
looking for something like this:

wget https://pip.org/install/install_pip.py
python install_pip.py

This is totally theoretical. wget doesn't work, the URL is made up, and 
install_pip.py is a fantasy of mine. ez_setup.py DOES exist for Setuptools, 
which is why I am trying to use it.

Thank you,

Zak

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


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread Dave Angel
On 19/9/2013 11:53, Neil Cerutti wrote:

> On 2013-09-18, Dave Angel  wrote:
>> On 18/9/2013 17:40, Neil Hodgson wrote:
>>
>>> Dave Angel:
>>>
 So is the bug in Excel, in Windows, or in the Python library?  Somebody
 is falling down on the job;  if Windows defines the string as ending at
 the first null, then the Python interface should use that when defining
 the text defined with CF_UNICODETEXT.
>>>
>>> Everything is performing correctly. win32clipboard is low-level 
>>> direct access to the Win32 clipboard API. A higher level API which is 
>>> more easily used from Python could be defined on top of this if anyone 
>>> was motivated.
>>>
>>> Neil
>>
>> Clearly you miss the point.  If the clipboard API is defined to
>> return a null-terminated string, then the problem is in the
>> Python library which doesn't do a strlen() (or the
>> wide-character equivalent;  I forget its name) on the results.
>
> Python can't really know if you're pasting text or a screenshot
> or what.
>

 CF_UNICODETEXT  gives it a pretty good clue.

But random832 has already mentioned that it's an ill-specified Windows
interface;  different programs deal with it differently.  No way that a
the Python library should deal with that.

-- 
DaveA


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


Re: Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread Skip Montanaro
> PIP would definitely do the trick. Does the MSI include PIP? If it does not 
> include PIP, then how can I easily install it from the command line? I am 
> looking for something like this:

Not yet, but I think just around the corner:

http://www.python.org/dev/peps/pep-0453/

Unlike most enhancements, this is proposed for inclusion in the next
micro releases of 2.7 and 3.3, not just in the next
normal-new-features-allowed version, 3.4.

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


Re: subprocess call is not waiting.

2013-09-19 Thread Terry Reedy

On 9/19/2013 7:42 AM, harish.barve...@gmail.com wrote:

subprocess.call(tempFileName, shell=True).communicate()


should raise an AttributeError as the int returned by subprocess.call 
does not have a .communicate method.



this process is not blocking.


Why do you think that? All function calls block until the function 
returns, at which point blocking ceases.  If you call 
Popen(someprog).communicate() and someprog runs quickly, you will hardly 
notice the blocking time.


--
Terry Jan Reedy

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


Re: Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread Skip Montanaro
> Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the 
> best way to install it from the command line in a future-proof manner (on 
> Windows)? I am imagining something like this:
>
> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
> python ez_setup.py
>
> However, (1) wget is not a Windows command. What is the Windows command? And 
> (2) is that URL the best possible URL? Or will that URL only download an old 
> version, and there is a better URL for new versions?

I am not a Windows person, but wouldn't pip do the trick?

https://pypi.python.org/pypi/pip/1.4.1

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


Re: django admin.py error

2013-09-19 Thread John Gordon
In  Gary Roach 
 writes:

> On 09/19/2013 11:15 AM, John Gordon wrote:

> > Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object
> > named 'membership'?

> Yes. The following is the top part of the models.py file: q

> class Membership(models.Model):
>  id_membership = models.IntegerField(unique=True, primary_key=True)

I see something named 'Membership', but nothing named 'membership'.
Python names are case-sensitive.

-- 
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


python 2.7 SSL to fetch servers notAfter date

2013-09-19 Thread Bryan Irvine
I'm trying to connect to an SSL application using client certs to grab the 
remote certs notAfter time.  When I connect using 'openssl s_client' and pass 
my client cert/key I can see it in the cert chain, but when I attempt to use 
get_peer_certificate() in python (2.7) I only get a blank dict and cannot pull 
the notAfter date.

I think this means that Python is unable to validate the cert, but I'm not sure 
the next steps to fix it.

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


Bug tracker breaks when given a username with an uppercase letter

2013-09-19 Thread random832
Registration appears to succeed, but does not allow login, and I can't
tell if email confirmation worked or not. I was able to register by
changing it to lowercase, but I had to guess what was happening.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread Prasad, Ramit
cyt...@m.allo.ws wrote:
> Hello All,
> 
> I really hate Windows, and I have only intermittent access to Windows 
> machines right now.
> 
> When I install Python 2.7 on Windows using the MSI installer, it definitely 
> does not modify the PATH
> variable. So I modify the PATH variable myself as follows:
> 
> setx PATH %PATH%;C:\Python27\
> 
> Question 1: The command above requires a reboot in order to take effect, at 
> least on Windows 8. How do
> I make it take effect immediately? Maybe if I repeat the same command again 
> with 'set' instead of
> 'setx'? Does 'set' affect the whole machine, or only the current CMD.EXE 
> session?

Set affects current session only.

"""
Setx provides the only command-line or programmatic way to directly and 
permanently set system environment values. System environment variables are 
manually configurable through Control Panel or through a registry editor. The 
set command, which is internal to the command interpreter (Cmd.exe), sets user 
environment variables for the current console window only.
""" ~ http://technet.microsoft.com/en-us/library/cc755104.aspx

Setx should not require a reboot, but might require user 
to log out and back in (or restart CMD). Also, note that
it modifies local environment by default and not system
environment.

[snip]

> 
> Question 3: Does the Windows MSI installer from Python.org include 
> Setuptools? python-guide.org
> implies that it does not include Setuptools, but I have never needed to 
> manually install Setuptools, I
> am always able to use easy_install right away. Is my memory warped, or 
> perhaps tainted by old Python
> installs on the same machine?

ActiveState's ActivePython MSI does include pip. FAQ says 
it also includes distribute which you could remove 
(I am guessing) but it will stop PyPM from working. 
I believe they also setup the PATH for you. I think
ActivePython might be a slightly better installer for
Windows users--at least that is what some people have 
recommended. I have not tried it myself, but it might
be worth taking a look.

> 
> Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the 
> best way to install it
> from the command line in a future-proof manner (on Windows)? I am imagining 
> something like this:
> 
> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
> python ez_setup.py
> 
> However, (1) wget is not a Windows command. What is the Windows command? And 
> (2) is that URL the best
> possible URL? Or will that URL only download an old version, and there is a 
> better URL for new
> versions?

The pip documentation uses the URL 
https://raw.github.com/pypa/pip/master/contrib/get-pip.py

pip documentation: https://pip.readthedocs.org/en/latest/installing.html 
 
> 
> Thank you,
> 
> Zak


~Ramit



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-19 Thread Ian Kelly
On Thu, Sep 19, 2013 at 1:22 PM, William Bryant  wrote:
> It was the other functions above it. Thanks. but I tried to do the while
> loop - I don't think I did it right, I am novice in python and I am 13 years
> old.

It should be structured like this:

while True:
answer = input("Enter yes/no:")
if answer in ('y', 'yes', 'new list'):
do_yes_stuff()
break
elif answer in ('n', 'no', 'close'):
do_no_stuff()
break
else:
print("Please enter y or n.")

If they answer 'yes' or 'no', then the break statement breaks out of
the while loop.  Otherwise the while loop continues from the top and
asks them again.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating rectangle with qt-designer

2013-09-19 Thread Rhodri James
On Wed, 18 Sep 2013 04:41:13 +0100, Mohsen Pahlevanzadeh  
 wrote:



Question: How can i draw a same rectangle with qt-designer?


First, posting an image to a newsgroup is pretty damn unfriendly.  Please  
don't do it again.


Second, wouldn't this question be better answered by the Qt Designer  
manual?  Which can be googled for trivially, by the way.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
https://mail.python.org/mailman/listinfo/python-list


Re: creating rectangle with qt-designer

2013-09-19 Thread Vincent Vande Vyvre

Le 18/09/2013 05:41, Mohsen Pahlevanzadeh a écrit :

Dear all,

I need to draw a rectangle , according to attached picture , you see a
rectangle in a form that enclosed with a text: "Rebuild Last Target".

Question: How can i draw a same rectangle with qt-designer?


Yours,
Mohsen


See : http://pyqt.sourceforge.net/Docs/PyQt4/qgroupbox.html

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-19 Thread Jake Angulo
Up Robert Kern's reply!

I was waiting for smtplib  to be
mentioned... finally!  Instead people simply answer philosophically.  I
dont want to judge whether OP is a troll or not - but i found a lot of
arrogant replies here.  I have also worked on an antispam project before,
and see through the intents of the OP, but I do not pretend to be a
moralist. I was hoping we would strictly discuss code or software
architecture here, not morality. Simple question, simple answer pls, in the
interest of the Python list.

To the OP:

You might want to google smtplib, and use that instead of os calling a
system command. Smtplib takes care of all the operating system's quirks for
you, and still uses the os native sendmail program.

On the other hand, the way you are sending email is highly suspect, trying
to spoof a domain, random email address, etc.  It is not easy to fool most
modern email servers nowadays - especially gmail's.  They verify first that
the sending domain matches the IP of the sender.  And if you are trying to
do this - it is neither Python's nor the OS fault.

Happy coding!


On Tue, Sep 17, 2013 at 10:51 PM, Robert Kern  wrote:

> On 2013-09-17 13:11, Ferrous Cranus wrote:
>
>  There are members here like Tim Chase who said that they find it
>> interesting to
>> be able to do what i proposed.
>>
>
> No, he didn't. He was using sarcasm in a vain attempt to inspire you to
> search the Python documentation where you could easily find the standard
> SMTP library.
>
>   
> http://docs.python.org/2/**library/smtplib
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma
>  that is made terrible by our own mad attempt to interpret it as though it
> had
>  an underlying truth."
>   -- Umberto Eco
>
> --
> https://mail.python.org/**mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Missing py2exe, needed 4 a gcode generator to engrave text in fancy ttf fonts in steel

2013-09-19 Thread Gene Heskett
Greetings;

Since the missing module is intended for making python stuff run standalone 
on a winderz box, I've no clue why it should be needed to build and make F-
Engrave run on my 10.04.4 LTS box, but it insists on loading it in the 
setup.py script that starts it the first time.

FWIW, cxfreeze is said, by synaptics search function to be the equ of the 
windows py2exe module.

Can someone take a look at 



Then this is what I get:
gene@coyote:~/src/F-Engrave-1.22_src$ python py2exe_setup.py
Traceback (most recent call last):
  File "py2exe_setup.py", line 4, in 
import py2exe
ImportError: No module named py2exe

And tell me how to fix this so it runs on an older linux box?

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page:  should be up!

Man is an animal that makes bargains: no other animal does this--
no dog exchanges bones with another.
-- Adam Smith
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-19 Thread Antoon Pardon
Op 20-09-13 05:56, Jake Angulo schreef:
> Up Robert Kern's reply!
> 
> I was waiting for smtplib  to
> be mentioned... finally!  Instead people simply answer philosophically.
>  I dont want to judge whether OP is a troll or not - but i found a lot
> of arrogant replies here.

That is nice. You don't like to judge the OP but you seem to have no
trouble judging others

> I have also worked on an antispam project
> before, and see through the intents of the OP, but I do not pretend to
> be a moralist.

That doesn't sound right after you judged other replies to be arrogant.

> I was hoping we would strictly discuss code or software
> architecture here, not morality. Simple question, simple answer pls, in
> the interest of the Python list.

Well I was hoping, we wouldn't be plagued by trolls or help-vampires
or at least that other wouldn't (spoon) feed them. I guess we can
always hope.

> To the OP:  
> 
> You might want to google smtplib, and use that instead of os calling a
> system command. Smtplib takes care of all the operating system's quirks
> for you, and still uses the os native sendmail program.

But that won't help in eliminating all the headers Nikos would like
to avoid. Like the receive line that will identify his host.

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


Can i run my python program under andriod?

2013-09-19 Thread Mohsen Pahlevanzadeh
Dear all,

I need to binary with distutils, and run it under android OS,
Do you have any experience?

yours,
Mohsen

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