Re: Message passing syntax for objects | OOPv2

2013-04-12 Thread Chris Angelico
On Sat, Apr 13, 2013 at 4:28 PM, Mark Janssen  wrote:
>> Mark, this proposal is out of place on a Python list, because it proposes an
>> object methodology radically different from any that is implemented in
>> Python now, or is even remotely likely to be implemented in Python in the
>> future.
>
> Wow, you guys are a bunch of ninnies.  I'm going to find some
> theoretical folks

Allow me to offer a serious suggestion: Just as C++ was originally
implemented as a preprocessor that produced C code (Cfront), implement
your language as a preprocessor that outputs Python (Pyfront?). Then
you can explore your ideas relatively cheaply (since you don't have to
implement a whole language) and portably (especially if you write your
front-end in Python itself)... and, most importantly, you'll have
*code* to show people, instead of half-baked theories.

Get some real solid code, then start demonstrating how your new system
is more expressive, or clearer, or what-have-you. It's much more
effective when you can discuss something that actually exists.

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


Re: Message passing syntax for objects | OOPv2

2013-04-12 Thread Mark Janssen
> Mark, this proposal is out of place on a Python list, because it proposes an
> object methodology radically different from any that is implemented in
> Python now, or is even remotely likely to be implemented in Python in the
> future.

Wow, you guys are a bunch of ninnies.  I'm going to find some
theoretical folks

MarkJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functional vs. Object oriented API

2013-04-12 Thread 88888 Dihedral
David M Chess於 2013年4月12日星期五UTC+8下午11時37分28秒寫道:
> > Roy Smith 
> 
> 
> 
> 
> > As part of our initial interview screen, we give
> applicants some small 
> 
> > coding problems to do.  One of the things we see a lot is what
> you could 
> 
> > call "Java code smell".  This is our clue that the
> person is really a 
> 
> > Java hacker at heart who just dabbles in Python but isn't really fluent.
>  
> 
> > ...
> 
> > It's not just LongVerboseFunctionNamesInCamelCase().  Nor is
> it code 
> 
> > that looks like somebody bought the Gang of Four patterns book and
> is 
> 

> > that maybe there's a class struggling to be written.
> 
> 
> 
> And I think equally to the point, even if you have
> only data, or only functions, right now, if the thing in question has that
> thing-like feel to it :) you will probably find yourself with both before
> you're done, so you might as well make it a class now...
> 
> 
> 
> DC

If it is not time-critical and no needs to convert into 
CYTHON then it does not matter too much.

But a well wrapped class structures with good documents can 
help others to use the python codes a lot.

If the part is intended to be time-critical in the low level 
part, then  avoiding seeking 4 levels of methods and properties
inside a loop is helpful in python programs to be executed 
in the run time.



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


Re: Unicode issue with Python v3.3

2013-04-12 Thread nagia . retsina
Τη Σάββατο, 13 Απριλίου 2013 4:41:57 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:
> On 11Apr2013 09:55, Nikos  wrote:
> 
> | Τη Πέμπτη, 11 Απριλίου 2013 1:45:22 μ.μ. UTC+3, ο χρήστης Cameron Simpson 
> έγραψε:
> 
> | > On 10Apr2013 21:50, nagia.rets...@gmail.com  
> wrote:
> 
> | > | the doctype is coming form the attempt of script metrites.py to open 
> and read the 'index.html' file.
> 
> | > | But i don't know how to try to open it as a byte file instead of an 
> tetxt file.
> 
> 
> 
> Lele Gaifax showed one way:
> 
> 
> 
> from codecs import open
> 
> with open('index.html', encoding='utf-8') as f:
> 
> content = f.read()
> 
> 
> 
> But a plain open() should also do:
> 
> 
> 
> with open('index.html') as f:
> 
> content = f.read()
> 
> 
> 
> if you're not taking tight control of the file encoding.
> 
> 
> 
> The point here is to get _text_ (i.e. str) data from the file, not bytes.
> 
> 
> 
> If the text turns out to be incorrectly decoded (i.e. incorrectly
> 
> reading the file bytes and assembling them into text strings) because
> 
> the default encoding is wrong, then you may need to read for Lele's
> 
> more verbose open() example to select the correct encoding.
> 
> 
> 
> But first ignore that and get text (str) instead of bytes.
> 
> If you're already getting text from the file, something later is
> 
> making bytes and handing it to print().
> 
> 
> 
> Another approach to try is to use
> 
>   sys.stdout.write()
> 
> instead of
> 
>   print()
> 
> 
> 
> The print() function will take _anything_ and write text of some form.
> 
> The write() function will throw an exception if it gets the wrong type of 
> data.
> 
> 
> 
> If sys.stdout is opened in binary mode then write() will require
> 
> bytes as data; strings will need to be explicitly turned into bytes
> 
> via .encode() in order to not raise an exception.
> 
> 
> 
> If sys.stdout is open in text mode, write() will require str data.
> 
> The sys.stdout file itself will transcribe to bytes for you.
> 
> 
> 
> If you take that route, at least you will not have confusion about
> 
> str versus bytes.
> 
> 
> 
> For an HTML output page I would advocate arranging that sys.stdout
> 
> is in text mode; that way you can do the natural thing and .write()
> 
> str data and lovely UTF-8 bytes will come out the other end.
> 
> 
> 
> If the above test (using .write() instead of print()) shows it to
> 
> be in binary mode we can fix that. But you need to find out.
> 
> 
> 
> You will want access to the error messages from the CGI environment;
> 
> do you have access to the web servers error_log? You can tail that
> 
> in a terminal while you reload the page to see what's going on.
> 
> 
> 
> | This works in the shell, but doesn't work on my website:
> 
> | 
> 
> | $ cat utf8.txt
> 
> | υλικό!Πρόκειται γ
> 
> 
> 
> Ok, so your terminal is using UTF-8 as its output coding. (And so
> 
> is your mail posting program, since we see it unmangled on my screen
> 
> here.)
> 
> 
> 
> | $ python3
> 
> | Python 3.2.3 (default, Oct 19 2012, 20:10:41)
> 
> | [GCC 4.6.3] on linux2
> 
> | Type "help", "copyright", "credits" or "license" for more information.
> 
> | >>> data = open('utf8.txt').read()
> 
> | >>> print(data)
> 
> | υλικό!Πρόκειται γ
> 
> 
> 
> Likewise.
> 
> 
> 
> However, in an exciting twist, I seem to recall that Python invoked
> 
> interactively with aterminal as output will have the default terminal
> 
> encoding in place on sys.stdout. Producing what you expect. _However_,
> 
> python invoked in a batch environment where stdout is not a terminal
> 
> (such as in the CGI environment producing your web page), that is
> 
> _not_ necessarily the case.
> 
> 
> 
> | >>> print(data.encode('utf-8'))
> 
> | 
> b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9
>  \xce\xb3\n'
> 
> | 
> 
> | See, the last line is what i'am getting on my website.
> 
> 
> 
> The above line takes your Unicode text in "data" and transcribed
> 
> it to bytes using UTF-8 as the encoding. And print() is then receiving
> 
> that bytes object and printing its str() representation as "b''".
> 
> That str is itself unicode, and when print passes it to sys.stdout,
> 
> _that_ transcribed the unicode "b'...'" string as bytes to your
> 
> terminal. Using UTF-8 based on the previous examples above, but
> 
> since all those characters are in the bottom 127 code range the
> 
> byte sequence will be the same if it uses ASCII or ISO8859-1 or
> 
> almost anything else:-)
> 
> 
> 
> As you can see, there's a lot of encoding/decoding going on behind
> 
> the scenes even in this superficially simple example.
> 
> 
> 
> | If i remove
> 
> | the encode('utf-8') part in metrites.py, the webpage will not show
> 
> | anything at all...
> 
> 
> 
> Ah, but data will be being output. The print() function _will_ be
> 
> writing "data" out in some form.  I suggest you remove the .encode()
> 
> and then examine the _sou

Re: [OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)]

2013-04-12 Thread Chris Angelico
On Sat, Apr 13, 2013 at 1:17 PM, Steven D'Aprano
 wrote:
> On Sat, 13 Apr 2013 03:33:29 +0100, Nobody wrote:
>> If you want to wait for the data written to be written to the physical
>> disk (in order to obtain specific behaviour with respect to an unclean
>> shutdown), use f.flush() followed by os.fsync(f.fileno()).
>
> If only it were that simple. It has been documented that some disks will
> lie, even when told to sync. When I say "some", I mean *most*. There's
> probably nothing you can do about it, apart from not using that model or
> brand of disk, so you have to just live with the risk.

It's often close to that simple. With most hard disks, you can make
them 100% reliable, but you may have to check some disk parameters (on
Linux, that's just a matter of writing to something in /proc
somewhere, don't remember the details but it's easy to check). The
worst offenders I've met are SSDs...

> USB sticks are especially nasty. I've got quite a few USB thumb drives
> where the "write" light keeps flickering for anything up to five minutes
> after the OS reports that the drive has been unmounted and is safe to
> unplug. I corrupted the data on these quite a few times until I noticed
> the light. And let's not even mention the drives that have no light at
> all...

... but you've met worse.

> But my favourite example of lying hard drives of all time is this:
>
> http://blog.jitbit.com/2011/04/chinese-magic-drive.html
>
> I want one of those!

Awesome! It's the new version of DoubleSpace / DriveSpace!

http://en.wikipedia.org/wiki/DriveSpace

(And its problems, according to that Wikipedia article, actually had
the same root cause - write caching that the user wasn't aware of.
Great.)

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


[OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)]

2013-04-12 Thread Steven D'Aprano
On Sat, 13 Apr 2013 03:33:29 +0100, Nobody wrote:

> On Fri, 12 Apr 2013 00:06:21 +, Steven D'Aprano wrote:
> 
>>> The close method is defined and flushing and closing a file, so it
>>> should not return until that's done.
>> 
>> But note that "done" in this case means "the file system thinks it is
>> done", not *actually* done. Hard drives, especially the cheaper ones,
>> lie. They can say the file is written when in fact the data is still in
>> the hard drive's internal cache and not written to the disk platter.
>> Also, in my experience, hardware RAID controllers will eat your data,
>> and then your brains when you try to diagnose the problem.
> 
> None of which is likely to be relevant here, 

Since we've actually identified the bug (the OP was using file.close 
without actually calling it), that's certainly the case :-)


[...]
> If you want to wait for the data written to be written to the physical
> disk (in order to obtain specific behaviour with respect to an unclean
> shutdown), use f.flush() followed by os.fsync(f.fileno()).

If only it were that simple. It has been documented that some disks will 
lie, even when told to sync. When I say "some", I mean *most*. There's 
probably nothing you can do about it, apart from not using that model or 
brand of disk, so you have to just live with the risk.

http://queue.acm.org/detail.cfm?id=2367378

USB sticks are especially nasty. I've got quite a few USB thumb drives 
where the "write" light keeps flickering for anything up to five minutes 
after the OS reports that the drive has been unmounted and is safe to 
unplug. I corrupted the data on these quite a few times until I noticed 
the light. And let's not even mention the drives that have no light at 
all...

But my favourite example of lying hard drives of all time is this:

http://blog.jitbit.com/2011/04/chinese-magic-drive.html

I want one of those!



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Chris Angelico
On Sat, Apr 13, 2013 at 12:33 PM, Nobody  wrote:
> But most of the time, there's no point. If you actually care about what
> happens in the event of an unclean shutdown, you typically also need to
> sync the directory, otherwise the file's contents will get sync'd but the
> file's very existence might not be.

Or just store your content in a PostgreSQL database, and let it worry
about all the platform-specific details of how to fsync reliably.

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Nobody
On Fri, 12 Apr 2013 00:06:21 +, Steven D'Aprano wrote:

>> The close method is defined and flushing and closing a file, so it
>> should not return until that's done.
> 
> But note that "done" in this case means "the file system thinks it is 
> done", not *actually* done. Hard drives, especially the cheaper ones, 
> lie. They can say the file is written when in fact the data is still in 
> the hard drive's internal cache and not written to the disk platter. 
> Also, in my experience, hardware RAID controllers will eat your data, and 
> then your brains when you try to diagnose the problem.

None of which is likely to be relevant here, as any subsequent access to
the file will reference the in-memory copy; the disk will only get
involved if the data has already been flushed from the OS' cache and has
to be read back in from disk.

write(), close(), etc return once the data has been written to the
OS' disk cache. At that point, the OS usually won't have even started
sending the data to the drive, let alone waited for the drive to report
(or claim) that the data has been written to the physical disk.

If you want to wait for the data written to be written to the physical
disk (in order to obtain specific behaviour with respect to an unclean
shutdown), use f.flush() followed by os.fsync(f.fileno()).

But most of the time, there's no point. If you actually care about what
happens in the event of an unclean shutdown, you typically also need to
sync the directory, otherwise the file's contents will get sync'd but the
file's very existence might not be.

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


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread Steven D'Aprano
On Fri, 12 Apr 2013 23:26:05 +, Cousin Stanley wrote:

>   The firefox browser keeps different sqlite database files for various
>   uses 

Yes, and I *really* wish they wouldn't. It's my number 1 cause of major 
problems with Firefox. E.g.

http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox


Using a database for such lightweight data as bookmarks is, in my 
opinion, gross overkill and adds to the complexity of Firefox. More
complexity leads to more bugs, e.g.:

https://bugzilla.mozilla.org/show_bug.cgi?id=465684#c11

https://bugzilla.mozilla.org/show_bug.cgi?id=431558


Please don't use a full-featured database if you don't need the overhead 
of ACID compliance. And if you do, well, Sqlite is not fully ACID compliant.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread Cameron Simpson
On 11Apr2013 09:55, Nikos  wrote:
| Τη Πέμπτη, 11 Απριλίου 2013 1:45:22 μ.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:
| > On 10Apr2013 21:50, nagia.rets...@gmail.com  wrote:
| > | the doctype is coming form the attempt of script metrites.py to open and 
read the 'index.html' file.
| > | But i don't know how to try to open it as a byte file instead of an tetxt 
file.

Lele Gaifax showed one way:

from codecs import open
with open('index.html', encoding='utf-8') as f:
content = f.read()

But a plain open() should also do:

with open('index.html') as f:
content = f.read()

if you're not taking tight control of the file encoding.

The point here is to get _text_ (i.e. str) data from the file, not bytes.

If the text turns out to be incorrectly decoded (i.e. incorrectly
reading the file bytes and assembling them into text strings) because
the default encoding is wrong, then you may need to read for Lele's
more verbose open() example to select the correct encoding.

But first ignore that and get text (str) instead of bytes.
If you're already getting text from the file, something later is
making bytes and handing it to print().

Another approach to try is to use
  sys.stdout.write()
instead of
  print()

The print() function will take _anything_ and write text of some form.
The write() function will throw an exception if it gets the wrong type of data.

If sys.stdout is opened in binary mode then write() will require
bytes as data; strings will need to be explicitly turned into bytes
via .encode() in order to not raise an exception.

If sys.stdout is open in text mode, write() will require str data.
The sys.stdout file itself will transcribe to bytes for you.

If you take that route, at least you will not have confusion about
str versus bytes.

For an HTML output page I would advocate arranging that sys.stdout
is in text mode; that way you can do the natural thing and .write()
str data and lovely UTF-8 bytes will come out the other end.

If the above test (using .write() instead of print()) shows it to
be in binary mode we can fix that. But you need to find out.

You will want access to the error messages from the CGI environment;
do you have access to the web servers error_log? You can tail that
in a terminal while you reload the page to see what's going on.

| This works in the shell, but doesn't work on my website:
| 
| $ cat utf8.txt
| υλικό!Πρόκειται γ

Ok, so your terminal is using UTF-8 as its output coding. (And so
is your mail posting program, since we see it unmangled on my screen
here.)

| $ python3
| Python 3.2.3 (default, Oct 19 2012, 20:10:41)
| [GCC 4.6.3] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> data = open('utf8.txt').read()
| >>> print(data)
| υλικό!Πρόκειται γ

Likewise.

However, in an exciting twist, I seem to recall that Python invoked
interactively with aterminal as output will have the default terminal
encoding in place on sys.stdout. Producing what you expect. _However_,
python invoked in a batch environment where stdout is not a terminal
(such as in the CGI environment producing your web page), that is
_not_ necessarily the case.

| >>> print(data.encode('utf-8'))
| 
b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9
 \xce\xb3\n'
| 
| See, the last line is what i'am getting on my website.

The above line takes your Unicode text in "data" and transcribed
it to bytes using UTF-8 as the encoding. And print() is then receiving
that bytes object and printing its str() representation as "b''".
That str is itself unicode, and when print passes it to sys.stdout,
_that_ transcribed the unicode "b'...'" string as bytes to your
terminal. Using UTF-8 based on the previous examples above, but
since all those characters are in the bottom 127 code range the
byte sequence will be the same if it uses ASCII or ISO8859-1 or
almost anything else:-)

As you can see, there's a lot of encoding/decoding going on behind
the scenes even in this superficially simple example.

| If i remove
| the encode('utf-8') part in metrites.py, the webpage will not show
| anything at all...

Ah, but data will be being output. The print() function _will_ be
writing "data" out in some form.  I suggest you remove the .encode()
and then examine the _source_ text of the web page, not its visible
form.

So: remove .encode(), reload the web page, "view page source"
(depends on your browser, it is ctrl-U in Firefox ((Cmd-U in firefox
on a Mac))).

I think a lot of the issue you have in this thread is that your
page is too complex. Make another page to do the same thing, and
start with nothing. Add stuff to it a single item at a time until
the page behaves incorrectly. Then you will know the exact item of
code that introduced the issue. And then that single item can be
examined in detail for the decode/encode issues.

The other issue in the thread is that people losing patience get
snarky. Re

Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread someone

On 04/13/2013 01:26 AM, Cousin Stanley wrote:

someone wrote:



So SQLite is very good for "practicing"



   Yes it is but it is also very good
   for much more than just practice 

   Check the wikipedia info 

 http://en.wikipedia.org/wiki/Sqlite


Very interesting...


 "It is arguably the most widely deployed database engine,
  as it is used today by several widespread browsers,
  operating systems, and embedded systems, among others"

   The firefox browser keeps different sqlite database files
   for various uses 


I should remember to use this in the future for my small apps...


   If you use firefox check its default directory
   and you will see several files with .sqlite
   file type extensions 

   Under debian debian linux 

 ~/.mozilla/firefox/*.default


You're right:

/home/myUser/.mozilla/firefox/pv079lxv.default/addons.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/chromeappsstore.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/content-prefs.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/cookies.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/downloads.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/extensions.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/formhistory.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/permissions.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/places.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/search.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/signons.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/urlclassifier3.sqlite
/home/myUser/.mozilla/firefox/pv079lxv.default/webappsstore.sqlite

Very interesting, I didn't knew that :-)


   Many programmers, including pythonistas,
   use sqlite for a convenient and persistent
   data store where data can be stashed now
   and used later in many different ways
   through the diversity of sql selections 


I'll try to do this in the future also... I just have to practice a bit 
more with the SQL commands, but now I can create, update, delete, query 
and I guess that's the most important things to know :-)


Thanks for your help and for providing interesting background info :-)


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


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread Cousin Stanley
someone wrote:

> 
> So SQLite is very good for "practicing"
> 

  Yes it is but it is also very good 
  for much more than just practice  

  Check the wikipedia info  

http://en.wikipedia.org/wiki/Sqlite

"It is arguably the most widely deployed database engine, 
 as it is used today by several widespread browsers, 
 operating systems, and embedded systems, among others"

  The firefox browser keeps different sqlite database files 
  for various uses  

  If you use firefox check its default directory 
  and you will see several files with .sqlite  
  file type extensions 

  Under debian debian linux  

~/.mozilla/firefox/*.default

  Many programmers, including pythonistas,
  use sqlite for a convenient and persistent 
  data store where data can be stashed now 
  and used later in many different ways 
  through the diversity of sql selections 


> Thanks again  

  You're welcome 

> I just love this python language

  Me too  :-)


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: CSV to matrix array

2013-04-12 Thread Miki Tebeka

> I have a CSV file with 20 rows and 12 columns and I need to store it as a 
> matrix.
If you can use pandas, the pandas.read_csv is what you want.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Javier Miranda
Keep the flattened data array others suggested, and then just split it like
this: *(replace `example_data`, `_array`, and `columns`)*

>>> example_data = range(15)

>>> split_array = lambda _array, colums: \

. . .[_array[i:i + colums] for i in \

. . .xrange(0, len(_array), colums)]

 >>> print split_array(example_data, 5)

[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]

Gist 

What do you guys think?


On Fri, Apr 12, 2013 at 12:46 PM, Dave Angel  wrote:

> On 04/12/2013 01:29 PM, Ana Dionísio wrote:
>
>> That only puts the data in one column, I wanted to separate it.
>>
>> For example:
>> data in csv file:
>>
>> 1 2 3 4 5
>> 7 8 9 10 11
>> a b c d e
>>
>> I wanted an array where I could pick an element in each position. In the
>> case above if I did print array[0][3] it would pick 4
>>
>>
> I know nothing about numpy.
>
> How about something like:
> import csv
> myreader = csv.reader()
> mylist = list(myreader)
>
>
> Presumably you can fill in the details.  Anyway, I think this will give
> you a list of lists, and perhaps you can convert that to a numpy array, if
> you really need one of those.
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
Javier Miranda
Mobile: +52 333 129 20 70
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page.

2013-04-12 Thread Terry Jan Reedy

On 4/12/2013 4:46 PM, Piotr Dobrogost wrote:

Hi!

I'd like to bring your attention to the question titled "Use HTTP/1.1
with SimpleHTTPRequestHandler" at
http://stackoverflow.com/q/15839718/95735 which reads; "When I use


I find the doc slightly confusing. The SO code uses BaseHTTPServer. The 
doc says "Usually, this module isn’t used directly," On the other hand, 
SimpleHTTPServer only defines a request handler and not a server itself.



HTTP/1.1 with SimpleHTTPRequestHandler, loading a page that pulls in
other resources will hang after the second resource." and there's a


What does 'hang' mean? Does the page get displayed? If so, 
server.serve_forever is supposes to 'hang'.



tiny test showing the problem. It's hard to believe that
SimpleHTTPServer doesn't handle such a simple task, does it? If I
checked correctly code is stuck in handle_one_request() method at
line 370 of server.py
(http://hg.python.org/cpython/file/d9893d13c628/Lib/http/server.py#l370)
but I can't see what's wrong. Any ideas?


The SO post says

class MyRequestHandler(SimpleHTTPRequestHandler):
#protocol_version = "HTTP/1.0"   # works
protocol_version = "HTTP/1.1"   # hangs

so this should be some sort of clue. The code says

569 # The version of the HTTP protocol we support.
570 # Set this to HTTP/1.1 to enable automatic keepalive
571 protocol_version = "HTTP/1.0"

The only substantive code I found using protocol_version (in the CPython 
default branch you linked to) is


300 if version_number >= (1, 1) and self.protocol_version >= "HTTP/1.1":
301 self.close_connection = 0

331 elif (conntype.lower() == 'keep-alive' and
332 self.protocol_version >= "HTTP/1.1"):
333 self.close_connection = 0
334 # Examine the headers and look for an Expect directive
335 expect = self.headers.get('Expect', "")
336 if (expect.lower() == "100-continue" and
337 self.protocol_version >= "HTTP/1.1" and
338 self.request_version >= "HTTP/1.1"):
339 if not self.handle_expect_100():
340 return False

I would re-test with the recently released 3.3.1 (and/or 2.7.4) to make 
sure nothing has changed


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


RE: im.py: a python communications tool

2013-04-12 Thread Prasad, Ramit
Neil Cerutti wrote:
> On 2013-04-12, Mark Janssen  wrote:
> > Possibily, but don't accept this view of the legal system.
> > Judges can be quite reasonable.  They don't want more time
> > taken for bullshit cases and would much prefer for things to be
> > settled (that is what their duty is -- to settle matters, not
> > to make lawyers wealthy).
> 
> Wishful thinking is the wrong way to approach any legal matter.
> 

He is not completely wishful (for USA). 
http://www.macrumors.com/2013/04/11/u-s-judge-expresses-frustration-at-apples-and-googles-use-of-litigation-as-business-strategy/

Of course, not sure if the frustration will actually lead to
an action or is just idle talk.


~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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: extract HTML table in a structured format

2013-04-12 Thread Prasad, Ramit
Jabba Laci
> Hi,
> 
> I wonder if there is a nice way to extract a whole HTML table and have the 
> result in a nice structured
> format. What I want is to have the lifetime table at the bottom of this page:
> http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with a 
> script until when my
> Ubuntu release is supported).
> 
> I could do it with BeautifulSoup or lxml but is there a better way? There 
> should be :)
> 

I know you already answered your question, but thought this might be helpful
in the future.

Wikipedia has an API for programmatic access.
http://www.mediawiki.org/wiki/API 


~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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: newbie question about confusing exception handling in urllib

2013-04-12 Thread Prasad, Ramit
Steven D'Aprano wrote:
> try:
> main()
> except Exception as err:
> log(err)
> print("Sorry, an unexpected error has occurred.")
> print("Please contact support for assistance.")
> sys.exit(-1)
> 
> 

I like the traceback[0] module for logging last exception thrown.
See traceback.format_exc() or traceback.print_exc().

trace = traceback.format_exc()
log.error('I was trying to do , but unexpected 
error.\n{0}'.format(trace))

[0] http://docs.python.org/2/library/traceback.html


~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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread someone

On 04/12/2013 06:58 PM, Cousin Stanley wrote:

someone wrote:


As you can see, on my system I
had to use:

   print row[0] , row[1]

instead of:

   print row[ 'xtime' ] , row[ 'col4' ]

I'm not sure exactly why


   The magic there is setting up the row_factory
   after the database connection 

 dbc = DBM.connect( 'some.sql3' )

 dbc.row_factory = DBM.Row


Ah, thanks a lot - now it works! This is much more "user-friendly"...


I don't really know what's the difference
between sqlite3 and mysql...


   MySQL is used through a client/server system
   where the db server is always running
   and client processes submit requests to it
   in the form of sql statements 

   SQLite is used as a stand-alone single process
   with no external server involved 


Ok, I see... So SQLite is very good for "practicing"... I'll remember 
that, thank you.



   Both speak sql but there are some differences
   mostly in data base connection strings
   and data type declarations 

   Basic sql selection is 

 select these fields
 from   these files
 where  these conditions are met

   And that part of sql doesn't vary much
   among different data base managers 


Great, thank you very much...

Looks like everything is on track now... I just have to sit and play 
with it and make a good interface with matplotlib, but I think I should 
be able to come up with something nice, based on the help I god in this 
thread...


Thanks again... I just love this python language - makes it possible to 
do so much, in so little time and without being an expert at all...




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


SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page.

2013-04-12 Thread Piotr Dobrogost
Hi!

I'd like to bring your attention to the question titled "Use HTTP/1.1 with 
SimpleHTTPRequestHandler" at http://stackoverflow.com/q/15839718/95735 which 
reads; "When I use HTTP/1.1 with SimpleHTTPRequestHandler, loading a page that 
pulls in other resources will hang after the second resource." and there's a 
tiny test showing the problem.
It's hard to believe that SimpleHTTPServer doesn't handle such a simple task, 
does it?
If I checked correctly code is stuck in handle_one_request() method at line 370 
of server.py 
(http://hg.python.org/cpython/file/d9893d13c628/Lib/http/server.py#l370) but I 
can't see what's wrong.
Any ideas?


Best regards,
Piotr Dobrogost
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread nagia . retsina
Τη Παρασκευή, 12 Απριλίου 2013 9:37:29 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> On Fri, Apr 12, 2013 at 8:36 AM,   wrote:
> 
> > Τη Παρασκευή, 12 Απριλίου 2013 4:29:51 μ.μ. UTC+3, ο χρήστης rusi έγραψε:
> 
> >> On Apr 12, 6:18 pm, nagia.rets...@gmail.com wrote:
> 
> >> > Well, instead of being a smartass it would be nice if you could actually 
> >> > help for once.
> 
> >>
> 
> >> Interesting!
> 
> >>
> 
> >> Among the things which you dont seem to know is the meaning of the
> 
> >> word 'once'.
> 
> >
> 
> > Same applies for you too. Stop being smartasses.
> 
> 
> 
> Please keep in mind that this is a community of volunteers.  Nobody
> 
> here is being paid for their time to help you fix your website, and if
> 
> you manage to irritate us in the process, we're likely to just walk
> 
> away from it.
> 
> 
> 
> I looked over the code that you have provided us with, and based on
> 
> that I could not see any reason why the html would be in the form of a
> 
> bytes instead of a str.  Since nobody else here seems to have any
> 
> further insight into the problem either, you're just going to have to
> 
> find a a way to debug the code.  If you cannot do that on your own,
> 
> then I suggest that you find a contractor who can, hire them, and
> 
> grant them the access they need to do a real debugging session.
> 
> 
> 
> I would also recommend that in the future you should stop deploying
> 
> untested code to your production website.  Set up a development
> 
> environment for yourself, make the changes there, and only deploy when
> 
> you know that everything is working.

I agree with what you say except form the fact that i try to irritate people.
Look at the thread and you will see who's irritating whom first.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: im.py: a python communications tool

2013-04-12 Thread Prasad, Ramit
Mark Janssen wrote:
> >> It doesn't have to say so, if it's not charging any money -- there's no
> >> expectation that you're getting anything at all!
> >
> > Of course there is. If Oprah Winfrey stands up and publicly says that
> > she's giving you a car, FOR FREE, no strings attached, and then gives you
> > a piece of old bubblegum, you have standing to sue for breach of promise.
> > If she gives you the car, but puts it down as a *prize* rather than a
> > gift, then there is a big, hefty string attached: income tax.
> 
> But you see, there's the critical difference.  First of all you're
> making two errors in your comparison.  Firstly, a *person* is saying
> that she's going to *do something for you*.  She's making a promise.
> If I put a piece of software online -- you're taking it!  That's #1
> (!)

Theoretically isn't putting a piece of software "online" akin to
publishing it? Following that logic, then there is the possibility 
of arguing an implicit promise that the software does what it is 
supposed to. Any bugs would be the responsibility of the developer. 

On a separate note, even if the judgment supports your view
and the developer is never responsible for damages, will you
still not be responsible for any court/lawyer fees? And
getting those fees paid by suitor will likely be another court case.


~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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-12 Thread Neil Cerutti
On 2013-04-12, Mark Janssen  wrote:
> Possibily, but don't accept this view of the legal system.
> Judges can be quite reasonable.  They don't want more time
> taken for bullshit cases and would much prefer for things to be
> settled (that is what their duty is -- to settle matters, not
> to make lawyers wealthy).

Wishful thinking is the wrong way to approach any legal matter.

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


Re: im.py: a python communications tool

2013-04-12 Thread Mark Janssen
On Fri, Apr 12, 2013 at 12:46 PM, Prasad, Ramit
 wrote:
> Mark Janssen wrote:
>> But you see, there's the critical difference.  First of all you're
>> making two errors in your comparison.  Firstly, a *person* is saying
>> that she's going to *do something for you*.  She's making a promise.
>> If I put a piece of software online -- you're taking it!  That's #1
>> (!)
>
> Theoretically isn't putting a piece of software "online" akin to
> publishing it? Following that logic, then there is the possibility
> of arguing an implicit promise that the software does what it is
> supposed to. Any bugs would be the responsibility of the developer.

It is akin to publishing it.  The law has not made a good distinction
about responsibility in this area.  But I'm telling you that unless
money is exchanged THERE IS NO AGREEMENT MADE, implicit or otherwise.
If there is no agreement, then another party can't blame you for
something you didn't promise.  Otherwise, I can blame you for
insulting my fashion sense.

> On a separate note, even if the judgment supports your view
> and the developer is never responsible for damages, will you
> still not be responsible for any court/lawyer fees?

If someone brings you to court and fails to make their case, they've
inconvenienced everyone.  The fair thing would be for the court to
require them to pay for your fees.

>And
> getting those fees paid by suitor will likely be another court case.

Possibily, but don't accept this view of the legal system.  Judges can
be quite reasonable.  They don't want more time taken for bullshit
cases and would much prefer for things to be settled (that is what
their duty is -- to settle matters, not to make lawyers wealthy).

Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread Roy Smith
In article ,
 Ian Kelly  wrote:

> I would also recommend that in the future you should stop deploying
> untested code to your production website.  Set up a development
> environment for yourself, make the changes there, and only deploy when
> you know that everything is working.

But that takes all the fun out of it :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread Ian Kelly
On Fri, Apr 12, 2013 at 8:36 AM,   wrote:
> Τη Παρασκευή, 12 Απριλίου 2013 4:29:51 μ.μ. UTC+3, ο χρήστης rusi έγραψε:
>> On Apr 12, 6:18 pm, nagia.rets...@gmail.com wrote:
>> > Well, instead of being a smartass it would be nice if you could actually 
>> > help for once.
>>
>> Interesting!
>>
>> Among the things which you dont seem to know is the meaning of the
>> word 'once'.
>
> Same applies for you too. Stop being smartasses.

Please keep in mind that this is a community of volunteers.  Nobody
here is being paid for their time to help you fix your website, and if
you manage to irritate us in the process, we're likely to just walk
away from it.

I looked over the code that you have provided us with, and based on
that I could not see any reason why the html would be in the form of a
bytes instead of a str.  Since nobody else here seems to have any
further insight into the problem either, you're just going to have to
find a a way to debug the code.  If you cannot do that on your own,
then I suggest that you find a contractor who can, hire them, and
grant them the access they need to do a real debugging session.

I would also recommend that in the future you should stop deploying
untested code to your production website.  Set up a development
environment for yourself, make the changes there, and only deploy when
you know that everything is working.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Dave Angel

On 04/12/2013 01:29 PM, Ana Dionísio wrote:

That only puts the data in one column, I wanted to separate it.

For example:
data in csv file:

1 2 3 4 5
7 8 9 10 11
a b c d e

I wanted an array where I could pick an element in each position. In the case 
above if I did print array[0][3] it would pick 4



I know nothing about numpy.

How about something like:
import csv
myreader = csv.reader()
mylist = list(myreader)


Presumably you can fill in the details.  Anyway, I think this will give 
you a list of lists, and perhaps you can convert that to a numpy array, 
if you really need one of those.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread rusi
On Apr 12, 10:12 pm, Ana Dionísio  wrote:
> Hi, thanks for yor answer! ;)
>
> Anyone has more suggestions?

My suggestions:

1. Tell us what was lacking in Mark's suggestion (to use loadtxt)
2. Read his postscript (for googlegroup posters).
[In case you did not notice your posts are arriving in doubles]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Ana Dionísio
That only puts the data in one column, I wanted to separate it. 

For example:
data in csv file:

1 2 3 4 5
7 8 9 10 11
a b c d e

I wanted an array where I could pick an element in each position. In the case 
above if I did print array[0][3] it would pick 4  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Jean-Michel Pichavant
- Original Message -
> Hello!
> 
> I have a CSV file with 20 rows and 12 columns and I need to store it
> as a matrix. I already created an array with zeros, but I don't know
> how to fill it with the data from the csv file. I have this script:
> 
> import numpy
> from numpy import array
> from array import *
> import csv
> 
> input = open('Cenarios.csv','r')
> cenario = csv.reader(input)
> 
> array=numpy.zeros([20, 12])
> 
> 
> I know I have to use for loops but I don't know how to use it to put
> the data the way I want. Can you help me?
> 
> Thanks!

did you try 

array = numpy.array(list(cenario))

?

JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Ana Dionísio
Hi, thanks for yor answer! ;)

Anyone has more suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread Cousin Stanley
someone wrote:

> As you can see, on my system I 
> had to use:
>
>   print row[0] , row[1]
>
> instead of:
>
>   print row[ 'xtime' ] , row[ 'col4' ]
>
> I'm not sure exactly why

  The magic there is setting up the row_factory 
  after the database connection  

dbc = DBM.connect( 'some.sql3' )

dbc.row_factory = DBM.Row

> I don't really know what's the difference 
> between sqlite3 and mysql...
 
  MySQL is used through a client/server system
  where the db server is always running 
  and client processes submit requests to it
  in the form of sql statements  

  SQLite is used as a stand-alone single process 
  with no external server involved 
  
  Both speak sql but there are some differences
  mostly in data base connection strings 
  and data type declarations 

  Basic sql selection is  

select these fields 
from   these files
where  these conditions are met 

  And that part of sql doesn't vary much
  among different data base managers 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: ANN: psutil 0.7.0 released

2013-04-12 Thread Stefan Behnel
Roy Smith, 12.04.2013 17:33:
>  Giampaolo Rodol� wrote:
> 
>> Hi there folks,
>> I'm pleased to announce the 0.7.0 release of psutil:
>> http://code.google.com/p/psutil/
> 
> I see a lot of these types of announcements.  May I suggest that people 
> add a short description of what that package is.  From the name, I can't 
> tell is this is about process status, or PostScript, or what.

And while we're at it, there's also a dedicated mailing list for Python
related announcements, which people commonly use for announcing important
releases of software packages:

http://mail.python.org/mailman/listinfo/python-announce-list

(And no, it's not that the unimportant ones should go here...)

Stefan


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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread 88888 Dihedral
Steven D'Aprano於 2013年4月12日星期五UTC+8上午8時06分21秒寫道:
> On Thu, 11 Apr 2013 19:55:53 +, Neil Cerutti wrote:
> 
> 
> 
> > On 2013-04-11, Rob Schneider  wrote:
> 
> >> Thanks. Yes, there is a close function call  before the copy is
> 
> >> launched. No other writes. Does Python wait for file close command to
> 
> >> complete before proceeding?
> 
> > 
> 
> > The close method is defined and flushing and closing a file, so it
> 
> > should not return until that's done.
> 
> 
> 
> But note that "done" in this case means "the file system thinks it is 
> 
> done", not *actually* done. Hard drives, especially the cheaper ones, 
> 
> lie. They can say the file is written when in fact the data is still in 
> 
> the hard drive's internal cache and not written to the disk platter. 
> 
> Also, in my experience, hardware RAID controllers will eat your data, and 
> 
> then your brains when you try to diagnose the problem.
> 
> 
Don't you model this as a non-blocking operation in 
your program?


> 
> I would consider the chance that the disk may be faulty, or the file 
> 
> system is corrupt. Does the problem go away if you write to a different 
> 
> file system or a different disk?
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven


Back-ups and read-back verifications are important for 
those who care.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functional vs. Object oriented API

2013-04-12 Thread David M Chess
> Roy Smith  

> As part of our initial interview screen, we give applicants some small 
> coding problems to do.  One of the things we see a lot is what you could 

> call "Java code smell".  This is our clue that the person is really a 
> Java hacker at heart who just dabbles in Python but isn't really fluent. 
 
> ...
> It's not just LongVerboseFunctionNamesInCamelCase().  Nor is it code 
> that looks like somebody bought the Gang of Four patterns book and is 
> trying to get their money's worth out of the investment.  The real dead 
> giveaway is when they write classes which contain a single static method 

> and nothing else.

I may have some lingering Java smell myself, although I've been working 
mostly in Python lately, but my reaction here is that's really I don't 
know "BASIC smell" or something; a class that contains a single static 
method and nothing else isn't wonderful Java design style either.

> That being said, I've noticed in my own coding, it's far more often that 

> I start out writing some functions and later regret not having initially 

> made it a class, than the other way around.  That's as true in my C++ 
> code as it is in my Python.

Definitely.

> Once you start having state (i.e. data) and behavior (i.e. functions) in 

> the same thought, then you need a class.  If you find yourself passing 
> the same bunch of variables around to multiple functions, that's a hint 
> that maybe there's a class struggling to be written.

And I think equally to the point, even if you have only data, or only 
functions, right now, if the thing in question has that thing-like feel to 
it :) you will probably find yourself with both before you're done, so you 
might as well make it a class now...

DC

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


Re: ANN: psutil 0.7.0 released

2013-04-12 Thread Roy Smith
In article ,
 Giampaolo Rodolà  wrote:

> Hi there folks,
> I'm pleased to announce the 0.7.0 release of psutil:
> http://code.google.com/p/psutil/

I see a lot of these types of announcements.  May I suggest that people 
add a short description of what that package is.  From the name, I can't 
tell is this is about process status, or PostScript, or what.

In this case, after clicking on the link, I see that "psutil is [...] 
for retrieving information on all running processes and system 
utilization".  Putting that one-liner up front in the announcement makes 
it easier for people to know if it's worth exploring further.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Mark Lawrence

On 12/04/2013 15:22, Ana Dionísio wrote:

Hello!

I have a CSV file with 20 rows and 12 columns and I need to store it as a 
matrix. I already created an array with zeros, but I don't know how to fill it 
with the data from the csv file. I have this script:

import numpy
from numpy import array
from array import *
import csv

input = open('Cenarios.csv','r')
cenario = csv.reader(input)

array=numpy.zeros([20, 12])


I know I have to use for loops but I don't know how to use it to put the data 
the way I want. Can you help me?

Thanks!



I'm no expert on numpy but there is a loadtxt function see 
http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Roy Smith
In article ,
 Rob Schneider  wrote:

> f.close

Well, there's your problem.  You're not calling close.  You forgot the 
()'s after the function name!
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: psutil 0.7.0 released

2013-04-12 Thread Giampaolo Rodolà
Hi there folks,
I'm pleased to announce the 0.7.0 release of psutil:
http://code.google.com/p/psutil/

This is mainly a bugfix release addressing a couple of high priority
issues on Linux and FreeBSD.
Complete list of bugfixes and enhancements is here:
https://psutil.googlecode.com/hg/HISTORY

=== New features ===

- psutil.get_boot_time()
- get/set process IO priority on Windows
- psutil.cpu_times() on Linux now includes new 'steal', 'guest' and
guest_nice' fields available on recent kernels
- psutil.cpu_times_percent() which provides utilization percentages
for each specific CPU time as is returned by cpu_times()
- source code has been migrated from SVN to Mercurial

=== Compatitility notes ===

- Process cmdline and ppid properties are no longer cached after first access
- psutil.error module is deprecated and scheduled for removal

=== Links ===

- Home: http://code.google.com/p/psutil
- Sources: http://psutil.googlecode.com/files/psutil-0.7.0.tar.gz
- Docs: http://code.google.com/p/psutil/wiki/Documentation


Please try out this new release and let me know if you experience any
problem by filing issues on the bug tracker.
Thanks in advance.


--- Giampaolo Rodola'

http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
http://code.google.com/p/pysendfile/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: name lookup failure using metaclasses with unittests

2013-04-12 Thread Terry Jan Reedy

On 4/12/2013 3:17 AM, Ulrich Eckhardt wrote:

Am 11.04.2013 10:19, schrieb Steven D'Aprano:

if sys.version >= '3':


Use sys.version_info >= (3,), otherwise your code breaks when upgrading
to Python 10 and greater. ;^)



The second question that came up was if there is a way to keep a
metaclass defined inside the class or if the only way is to provide it
externally. [...]


Not in general, since the metaclass has to exist independently of the
class.


Thanks for your explanations, they are appreciated.


 > The class is an instance of your metaclass. That means that the
 > metaclass must exist first, so it can be instantiated when you
 > define the class.

I don't like the approach to define the code to post-process a class
before defining the class. It's a bit like top-posting, it messes up the
reading order. Since I really intend to post-process the class, it seems
that metaclasses are simply not the right tool.


Using a post-processing object as a metaclass or decorator necessarily 
requires predefinition. Such objects are usually used more than once.


For one-off postprocessing, I probably would not bother.


At the moment, this leaves me with two options:

1. post-process the class

class X:
 pass
# attach constants to clas X
for i in (1, 2, 3):
 setattr(X, 'f{}' % i, i)

2. generate code inline

class Y: pass
 # generate constants in local (class-)namespace
 for i in (1, 2, 3):
 locals()['f{}' % i] = i


Mutating class locals() currently works in CPython, but is explicitly 
not guaranteed to work by the language definition.



In both cases, variables (loop variable 'i') are leaked into the
surrounding namespace, which is kind-of ugly. The second approach also
seems a bit hackish and I can't use the class-in-definition there, which
is limiting when you want to attach e.g. constants of type X to X.



Also PEP 3115 "Metaclasses in Python 3000"[2] seems to
consider postprocessing of a class definition as better handled by a
class decorator, which is something I haven't looked at yet.


Generally, class decorators are less brain-melting than metaclasses.


Alas, they also need to be defined before the class, messing with the
mentioned order of declaration. They can be used to call a class
function though which then does the necessary postprocessing...

3. post-process the class triggered with decorator

def postprocess_class(cls):
 """invoke postprocess() on the decorated object"""
 cls.postprocess()
 del cls.postprocess
 return cls

@postprocess_class
class Z:
 @classfunction
 def postprocess(cls):
 # attach constants to class
 for i in (1, 2, 3):
 setattr(cls, 'f{}' % i, i)


I guess I'll stay with variant 1 for now, since it requires the least
amount of code and the least amount of questions from other developers
here.



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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Roy Smith
In article <51674ffc$0$29977$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Thu, 11 Apr 2013 19:55:53 +, Neil Cerutti wrote:
> 
> > On 2013-04-11, Rob Schneider  wrote:
> >> Thanks. Yes, there is a close function call  before the copy is
> >> launched. No other writes. Does Python wait for file close command to
> >> complete before proceeding?
> > 
> > The close method is defined and flushing and closing a file, so it
> > should not return until that's done.
> 
> But note that "done" in this case means "the file system thinks it is 
> done", not *actually* done. Hard drives, especially the cheaper ones, 
> lie. They can say the file is written when in fact the data is still in 
> the hard drive's internal cache and not written to the disk platter. 
> Also, in my experience, hardware RAID controllers will eat your data, and 
> then your brains when you try to diagnose the problem.
> 
> I would consider the chance that the disk may be faulty, or the file 
> system is corrupt. Does the problem go away if you write to a different 
> file system or a different disk?

It is *possible* that this is the problem, but it's really way far out 
on the long tail of possibilities.  If the file system were corrupted or 
the disk faulty, the odds are you would be seeing all sorts of other 
problems.  And this would not be anywhere near as repeatable as the OP 
is describing.

Think horses, not zebras.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Roy Smith
In article ,
 Cameron Simpson  wrote:

> 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks,
> and the last partial block (to make it up to 47970) didn't get
> written (at the OS level).

Yeah, this sounds like a good diagnosis.

BTW, the dtruss command I recommended in my earlier post would confirm 
this.  But, to be honest, it's such a likely scenario that it hardly 
needs confirmation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Terry Jan Reedy

On 4/12/2013 3:32 AM, Chris Angelico wrote:

On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider  wrote:



The close method is defined and flushing and closing a file, so

it should not return until that's done.



What command are you using to create the temp file?




re command to write the file:
f=open(fn,'w')
... then create HTML text in a string
f.write(html)
f.close


Hold it one moment... You're not actually calling close. The file's
still open. Is that a copy/paste problem, or is that your actual code?

In Python, a function call ALWAYS has parentheses after it. Evaluating
a function's name like that returns the function (or method) object,
which you then do nothing with. (You could assign it someplace, for
instance, and call it later.) Try adding empty parens:

f.close()

and see if that solves the problem. Alternatively, look into the
'with' statement and the block syntax that it can give to I/O
operations.


I say *definitely* use a 'with' statement. Part of its purpose is to 
avoid close bugs.



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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Roy Smith
In article ,
 Rob Schneider  wrote:

> Source (correct one) is 47,970 bytes. Target after copy of 45,056 bytes.  
> I've tried changing what gets written to change the file size. It is usually 
> this sort of difference.
> 
> The file system is Mac OS Extended Journaled (default as out of the box).  

Is it always the tail end of the file that gets truncated, or is it 
missing (or mutating) data in the middle of the file?  I'm just grasping 
at straws here, but maybe it's somehow messing up line endings (turning 
CRLF pairs into just LF), or using some other kind of encoding for 
unicode characters?

If you compare the files with cmp, does it say:

$ cmp original truncated 
cmp: EOF on truncated

that's what I would expect if it's a strict truncation.  If it says 
anything else, you've got a data munging problem.

What I would normally do around this time is run a system call trace on 
the process to watch all the descriptor related (i.e. open, create, 
write) system calls.   On OSX, that means dtruss.  Unfortunately, I'm 
not that familiar with the OSX variant so I can't give you specific 
advice about which options to use.

When you can see the system calls, you know exactly what your process is 
doing.  You should be able to see the output file being opened and a 
descriptor returned, then find all the write() calls to that descriptor.  
You'll also be able to find any other system calls on that pathname 
after the descriptor is closed.

Please report back what you find!

Oh, another trick you might want to try is making the output file path 
/dev/stdout and redirecting the output into a file with the shell.  See 
if that makes any difference.  Or, try something like (assuming the -o 
option to your script sets the output filename):

python my_prog.py -o /dev/stdout | dd bs=1 of=xxx

That will do a couple of things.  First, dd will report how many bytes 
it read and wrote, so you can see if that's the correct number.  Also, 
since your process will no longer be writing to a real file, if anything 
is doing something weird like a seek() after you're done writing, that 
will fail since you can't seek() on a pipe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread nagia . retsina
Τη Παρασκευή, 12 Απριλίου 2013 4:29:51 μ.μ. UTC+3, ο χρήστης rusi έγραψε:
> On Apr 12, 6:18 pm, nagia.rets...@gmail.com wrote:
> 
> > Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> > έγραψε:
> 
> >
> 
> > > On Fri, Apr 12, 2013 at 10:50 PM,   wrote:
> 
> >
> 
> > > > Someone HEELP ME!!
> 
> >
> 
> > >http://youtu.be/VxMYwjp8t0o
> 
> >
> 
> > > ChrisA
> 
> >
> 
> > Well, instead of being a smartass it would be nice if you could actually 
> > help for once.
> 
> 
> 
> Interesting!
> 
> Among the things which you dont seem to know is the meaning of the
> 
> word 'once'.

Same applies for you too. Stop being smartasses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functional vs. Object oriented API

2013-04-12 Thread Mitya Sirenef

On 04/12/2013 10:19 AM, Roy Smith wrote:

As part of our initial interview screen, we give applicants some small
coding problems to do.  One of the things we see a lot is what you could
call "Java code smell".  This is our clue that the person is really a
Java hacker at heart who just dabbles in Python but isn't really fluent.
It's kind of like how I can walk into a Spanish restaurant and order
dinner or enquire where the men's room is, but everybody knows I'm a
gringo as soon as I open my mouth.

It's not just LongVerboseFunctionNamesInCamelCase().  Nor is it code
that looks like somebody bought the Gang of Four patterns book and is
trying to get their money's worth out of the investment.  The real dead
giveaway is when they write classes which contain a single static method
and nothing else.

That being said, I've noticed in my own coding, it's far more often that
I start out writing some functions and later regret not having initially
made it a class, than the other way around.



I've absolutely noticed the same thing for myself, over and over
again. I can't remember writing a class that I've regretted is not
a few functions, although it must have happened a few times.   -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


CSV to matrix array

2013-04-12 Thread Ana Dionísio
Hello!

I have a CSV file with 20 rows and 12 columns and I need to store it as a 
matrix. I already created an array with zeros, but I don't know how to fill it 
with the data from the csv file. I have this script:

import numpy
from numpy import array
from array import *
import csv

input = open('Cenarios.csv','r')
cenario = csv.reader(input)

array=numpy.zeros([20, 12])


I know I have to use for loops but I don't know how to use it to put the data 
the way I want. Can you help me?

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread someone

On 2013-04-11 20:44, Cousin Stanley wrote:

Cousin Stanley wrote:


   The stand-alone sqlite interpreter can first be used
   to create an empty database named some.sql3
   and create a table named  xdata  in that data base 

 sqlite3 some.sql3 '.read xdata_create.sql'


   This step can also be done in python
   without using the stand-alone sqlite interpreter 


Ah, that's great (and even better so I don't have to create the 
xdata_create.sql file) - thank you!


I collected what you wrote and put together this script:

=
#!/usr/bin/python

import sqlite3 as DBM
import ipdb

# ls = [ ] # this seems to be un-used ?
dbc = DBM.connect( 'some.sql3' )
cur = dbc.cursor()

fs = open( 'some.csv' )
if 0: # select whether to create new database file or query from it?
if 0: # switch between "create table xdata" and "... if not exists"
list_sql = [
'create table xdata ',
'( ',
'  xdate  integer , ',
'  xtime  integer , ',
'  col1   real , ',
'  col2   integer , ',
'  col3   integer , ',
'  col4   real , ',
'  col5   integer , ',
'  col6   integer ',
') ;' ]
else:
list_sql = [
  'create table if not exists xdata ' ,
  '( ' ,
  '  xdate  integer , ' ,
  '  xtime  integer , ' ,
  '  col1   real, ' ,
  '  col2   integer , ' ,
  '  col3   integer , ' ,
  '  col4   real, ' ,
  '  col5   integer , ' ,
  '  col6   integer   ' ,
  ') ; ' ]
# -
str_sql = '\n'.join( list_sql )
cur.execute( str_sql )
# -
# Insert data from input file fs ("some.csv")
sql = 'insert into xdata values( ? , ? , ? , ? , ? , ? , ? , ? )'
for row in fs :
dt, col1, col2, col3, col4,col5, col6 = row.strip().split(',' )
xdate , xtime = dt.split( 'T' )
xtuple = ( xdate, xtime, col1, col2, col3, col4, col5, col6 )
cur.execute( sql , xtuple )
dbc.commit()

else:
list_sql = [
  'select xtime , col4' ,
  'from   xdata' ,
  'where  xtime >= 8  and  xtime <= 81104 ; ' ]
str_sql = '\n'.join( list_sql )
cur.execute( str_sql )
for row in cur :
#ipdb.set_trace()
# I get: TypeError: "tuple indices must be integers, not str"
# "ipdb> row" says: "(8, 46120.0)"
#print row[ 'xtime' ] , row[ 'col4' ]
print row[0] , row[1]

fs.close()
dbc.close()
=

I think I can learn a lot from google, based on this code - I'm very 
grateful for your help!


Now I just need to make a nice interface and couple it to matplotlib, so 
it's easy to plot - I think there's a good chance that I can come up 
with a good solution from here, based on the help I got from you people...


Thanks again!

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


Re: Functional vs. Object oriented API

2013-04-12 Thread Roy Smith
In article <51678b94$0$29977$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> - If you have a complicated interface, or data with complicated internal 
> state, the best solution is to use a custom object with methods.
> 
> - But if your interface is simple, and the data is simple, it is more 
> efficient to stick to lightweight built-ins [...]
> 
> - If the *only* reason you use a class is to keep the data together, 
> that's very much a Java design.

As part of our initial interview screen, we give applicants some small 
coding problems to do.  One of the things we see a lot is what you could 
call "Java code smell".  This is our clue that the person is really a 
Java hacker at heart who just dabbles in Python but isn't really fluent.  
It's kind of like how I can walk into a Spanish restaurant and order 
dinner or enquire where the men's room is, but everybody knows I'm a 
gringo as soon as I open my mouth.

It's not just LongVerboseFunctionNamesInCamelCase().  Nor is it code 
that looks like somebody bought the Gang of Four patterns book and is 
trying to get their money's worth out of the investment.  The real dead 
giveaway is when they write classes which contain a single static method 
and nothing else.

That being said, I've noticed in my own coding, it's far more often that 
I start out writing some functions and later regret not having initially 
made it a class, than the other way around.  That's as true in my C++ 
code as it is in my Python.

In my mind, classes are all about data.  If there's no data (i.e. no 
stored state), you should be thinking a collection of functions.  On the 
other hand, if there's ONLY data and no behavior, then you should be 
thinking namedtuple (which is really just a shortcut way to write a 
trivial class).

Once you start having state (i.e. data) and behavior (i.e. functions) in 
the same thought, then you need a class.  If you find yourself passing 
the same bunch of variables around to multiple functions, that's a hint 
that maybe there's a class struggling to be written.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-12 Thread someone

On 2013-04-11 19:58, Cousin Stanley wrote:

someone wrote:



I want to put this table into an appropriate container
such that afterwards I want to:

1) Put the data into a mySql-table



   You might consider using sqlite3 as a database manager
   since it is  "batteries included"  with python 

   The stand-alone sqlite interpreter can first be used
   to create an empty database named some.sql3
   and create a table named  xdata  in that data base 

 sqlite3 some.sql3 '.read xdata_create.sql'

   where the file  xdata_create.sql  contains 

 create table xdata
 (
  xdate  integer ,
  xtime  integer ,
  col1   real ,
  col2   integer ,
  col3   integer ,
  col4   real ,
  col5   integer ,
  col6   integer
 ) ;


Oh, thank you very much! Now I understand this (I haven't really worked 
much with sql before, so this was/is new to me, thanks!).



   The csv data file can then be inserted into the xdata table
   in the  some.sql3  database via python 

 and ...

# python data selection example
# for column 4 between 8 and 9


I combined both code snippets into:

==
#!/usr/bin/python

import sqlite3 as DBM
import ipdb

fs = open( 'some.csv' )
ls = [ ]
dbc = DBM.connect( 'some.sql3' )
cur = dbc.cursor()
if 0:
sql = 'insert into xdata values( ? , ? , ? , ? , ? , ? , ? , ? )'
for row in fs :
dt, col1, col2, col3, col4,col5, col6 = row.strip().split(',' )
xdate , xtime = dt.split( 'T' )
xtuple = ( xdate, xtime, col1, col2, col3, col4, col5, col6 )
cur.execute( sql , xtuple )
dbc.commit()
else:
list_sql = [
  'select xtime , col4' ,
  'from   xdata' ,
  'where  xtime >= 8  and  xtime <= 9 ; ' ]
str_sql = '\n'.join( list_sql )
cur.execute( str_sql )
for row in cur :
#ipdb.set_trace()
# I get: TypeError: "tuple indices must be integers, not str"
# "ipdb> row" says: "(8, 46120.0)"
#print row[ 'xtime' ] , row[ 'col4' ]
print row[0] , row[1]

fs.close()
dbc.close()
==

I don't fully understand it yet, but it's nice to see that it works! 
Thank you very much for that! Now I'll have to concentrate on figuring 
out how/why it works :-)



   You can be creative with the data selections
   and pass them off to be plotted as needed 


Yes, I understand. Thank you very much. As you can see, on my system I 
had to use:


print row[0] , row[1]

instead of:

print row[ 'xtime' ] , row[ 'col4' ]

I'm not sure exactly why - is it because you have another version of 
sqlite3 ? This is a bit strange, but anyway I can live with that - at 
least for now...



   If mysql is used instead of sqlite3
   you should only have to monkey with
   the data type declarations in xdata_create.sql
   and the  dbc.connect  strings in the python code 


Actually I didn't knew anything about this sqlite3 before now. This is 
the first time I try it out, so I don't really know what's the 
difference between sqlite3 and mysql...


But thank you very much for providing some code I can now study and 
learn from !!! Much appreciated




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


Re: USBLock : lock/unlock your computer with a USB key

2013-04-12 Thread Schneider

On 11.04.2013 22:16, Ian Kelly wrote:

On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman  wrote:

On 04/11/2013 04:13 AM, Sven wrote:

Yes, I had the idea to add bluetooth too, removes the whole plugging and
unplugging spiel. I might start work on that,
and if anyone else wants to dive in and help, feel free. I will probably
need to refactor the Listener a little, or
create a USB and BT listener class.


Doesn't BlueTooth have a 30 foot range?  For locking I'd rather be at 10 or
even 5 feet away.

Pair it with a Google Glass and have it lock after you've stopped
looking at the screen for 30 seconds.


Maybe not with Google Glass, but with a web cam placed on top of the 
screen. Like Samsung does since the Galaxy S III.
There it just happens the other way round: no lock as long as you have 
your face in front of the phone.


bg,
Johannes

--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390

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


Re: Unicode issue with Python v3.3

2013-04-12 Thread rusi
On Apr 12, 6:18 pm, nagia.rets...@gmail.com wrote:
> Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> έγραψε:
>
> > On Fri, Apr 12, 2013 at 10:50 PM,   wrote:
>
> > > Someone HEELP ME!!
>
> >http://youtu.be/VxMYwjp8t0o
>
> > ChrisA
>
> Well, instead of being a smartass it would be nice if you could actually help 
> for once.

Interesting!
Among the things which you dont seem to know is the meaning of the
word 'once'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread Chris Angelico
On Fri, Apr 12, 2013 at 11:18 PM,   wrote:
> Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> έγραψε:
>> On Fri, Apr 12, 2013 at 10:50 PM,   wrote:
>>
>> > Someone HEELP ME!!
>>
>> http://youtu.be/VxMYwjp8t0o
>>
>> ChrisA
>
>
> Well, instead of being a smartass it would be nice if you could actually help 
> for once.

Yeah, I'm done with that. Your whining ran through my patience a few
posts ago. But you should feel special; I clipped that just for you.

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


Re: Unicode issue with Python v3.3

2013-04-12 Thread nagia . retsina
Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Fri, Apr 12, 2013 at 10:50 PM,   wrote:
> 
> > Someone HEELP ME!!
> 
> 
> 
> http://youtu.be/VxMYwjp8t0o
> 
> 
> 
> ChrisA


Well, instead of being a smartass it would be nice if you could actually help 
for once.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-12 Thread Chris Angelico
On Fri, Apr 12, 2013 at 10:50 PM,   wrote:
> Someone HEELP ME!!

http://youtu.be/VxMYwjp8t0o

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


Re: Unicode issue with Python v3.3

2013-04-12 Thread nagia . retsina
Someone HEELP ME!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Mark Lawrence

On 12/04/2013 13:07, Rob Schneider wrote:

On Friday, 12 April 2013 10:22:21 UTC+1, Chris Angelico  wrote:

On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider  wrote:


   f.close


Yep, there's the problem! See my previous post for details. Change this to:

f.close()

and you should be sorted.

ChrisA


Slapping forehead ... hard.  Thanks!



a) We've all done it :)
b) The print function/statement or Python's interactive mode are awesome 
in situations like this.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Rob Schneider
On Friday, 12 April 2013 10:22:21 UTC+1, Chris Angelico  wrote:
> On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider  wrote:
> 
> >   f.close
> 
> 
> 
> Yep, there's the problem! See my previous post for details. Change this to:
> 
> 
> 
> f.close()
> 
> 
> 
> and you should be sorted.
> 
> 
> 
> ChrisA

Slapping forehead ... hard.  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Message passing syntax for objects | OOPv2

2013-04-12 Thread Ned Batchelder


On 4/11/2013 9:57 PM, Mark Janssen wrote:

Okay peeps, I'm re-opening this thread, because despite being hijacked
by naysayers, the merit of the underlying idea I think still has not
been communicated or perceived adequately.
Mark, this proposal is out of place on a Python list, because it 
proposes an object methodology radically different from any that is 
implemented in Python now, or is even remotely likely to be implemented 
in Python in the future.


Everyone else, there's no need to skewer Mark for off-topic things like 
tweets on topics other than Python.  We can be civil, surely.


--Ned.
--
http://mail.python.org/mailman/listinfo/python-list


Re: USBLock : lock/unlock your computer with a USB key

2013-04-12 Thread Dylan Evans
On Fri, Apr 12, 2013 at 6:16 AM, Ian Kelly  wrote:

> On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman  wrote:
> > On 04/11/2013 04:13 AM, Sven wrote:
> >>
> >> Yes, I had the idea to add bluetooth too, removes the whole plugging and
> >> unplugging spiel. I might start work on that,
> >> and if anyone else wants to dive in and help, feel free. I will probably
> >> need to refactor the Listener a little, or
> >> create a USB and BT listener class.
> >
> >
> > Doesn't BlueTooth have a 30 foot range?  For locking I'd rather be at 10
> or
> > even 5 feet away.
>
>
I guess it depends on your needs, I'd want it locked when i wander out of
the office.


> Pair it with a Google Glass and have it lock after you've stopped
> looking at the screen for 30 seconds.
>

That would be awesome.


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



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Message passing syntax for objects | OOPv2

2013-04-12 Thread Mark Lawrence

On 12/04/2013 02:57, Mark Janssen wrote:

[dross snipped]

A summary here http://pinterest.com/pin/464293042804330899/

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Chris Angelico
On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider  wrote:
>   f.close

Yep, there's the problem! See my previous post for details. Change this to:

f.close()

and you should be sorted.

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Rob Schneider
On Friday, 12 April 2013 09:26:21 UTC+1, Cameron Simpson  wrote:
> 
> | > > Question: is the size of the incomplete file a round number? (Like
> 
> | > > a multiple of a decent sized power of 2>)
> 
> [...]
> 
> | Source (correct one) is 47,970 bytes. Target after copy of 45,056
> 
> | bytes.  I've tried changing what gets written to change the file
> 
> | size. It is usually this sort of difference.
> 
> 
> 
> 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks,
> 
> and the last partial block (to make it up to 47970) didn't get
> 
> written (at the OS level).
> 
> 
> 
> Earlier you wrote:
> 
> | I have created a file in temp space, then use the function
> 
> | "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname".
> 
> and:
> 
> | Yes, there is a close function call  before the copy is launched. No other 
> writes.
> 
> | Does Python wait for file close command to complete before proceeding?
> 
> 
> 
> Please show us the exact code used to make the temp file.
> 
> 
> 
> I would guess the temp file has not been closed (or flushed) before
> 
> the call to copyfile.
> 
> 
> 
> If you're copying data to a tempfile, it will only have complete
> 
> buffers (i.e. multiples of 4096 bytes) in it until the final flush
> 
> or close.
> 
> 
> 
> So I'm imagining something like:
> 
> 
> 
>   tfp = open(tempfilename, "w")
> 
>   ... lots of tfp.write() ...
> 
>   shutil.copyfile(tempfilename, newfilename)
> 
> 
> 
> Note above no flush or close of tfp. So the final incomplete I/O
> 
> buffer is still in Python's memory; it hasn't been actually written
> 
> to the temp file because the buffer has not been filled, and the file
> 
> has not been closed.
> 
> 
> 
> Anyway, can you show us the relevant bits of code involved?
> 
> 
> 
> Cheers,
> 
> -- 
> 
> Cameron Simpson 
> 
> 
> 
> Processes are like potatoes.- NCR device driver manual

Thanks for the observation. 

Code (simplified but results in same flaw) (which a close, far as I can tell).

def CreateSpeakerList1():
import shutil
import filecmp
import os.path 

t=get_template('speaker_list.html')
fn=TEMP_DIR+SOC_SPEAKER_LIST
fn=tempfile.gettempdir()+"/"+SOC_SPEAKER_LIST
f=open(fn,'w')
speaker_list=Speaker.objects.order_by('status__order','targetmtg__date')
print "Creating " + SOC_SPEAKER_LIST +  " ..."
html=(smart_str(t.render(Context(
{
'css_include_file':CSS_INCLUDE_FILE,
'css_link':False,
'title': ORG_NAME+" Speaker List",
'speaker_list': speaker_list,
}
f.write(html)
f.close
print "Wrote "+fn
shutil.copyfile(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST)
print "Filecompare 
:",filecmp.cmp(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST)
print "Statinfo:"+fn+":\n", os.stat(fn)
print "Statinfo:"+SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST+"\n", 
os.stat(SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST)
return

Output on latest run:

Creating speakers.htm ...
Wrote /var/folders/p_/n5lktj2n0r938_46jyqb52g4gn/T/speakers.htm
Filecompare : True
Statinfo:/var/folders/p_/n5lktj2n0r938_46jyqb52g4gn/T/speakers.htm:
posix.stat_result(st_mode=33188, st_ino=32332374, st_dev=16777218L, st_nlink=1, 
st_uid=501, st_gid=20, st_size=45056, st_atime=1365758139, st_mtime=1365758139, 
st_ctime=1365758139)
Statinfo:/Users/rmschne/Documents/ScottishOilClub/Output/speakers.htm
posix.stat_result(st_mode=33188, st_ino=32143886, st_dev=16777218L, st_nlink=1, 
st_uid=501, st_gid=20, st_size=45056, st_atime=1365758029, st_mtime=1365758139, 
st_ctime=1365758139)


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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Cameron Simpson
On 11Apr2013 23:32, Rob Schneider  wrote:
| > > Question: is the size of the incomplete file a round number? (Like
| > > a multiple of a decent sized power of 2>)
[...]
| Source (correct one) is 47,970 bytes. Target after copy of 45,056
| bytes.  I've tried changing what gets written to change the file
| size. It is usually this sort of difference.

45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks,
and the last partial block (to make it up to 47970) didn't get
written (at the OS level).

Earlier you wrote:
| I have created a file in temp space, then use the function
| "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname".
and:
| Yes, there is a close function call  before the copy is launched. No other 
writes.
| Does Python wait for file close command to complete before proceeding?

Please show us the exact code used to make the temp file.

I would guess the temp file has not been closed (or flushed) before
the call to copyfile.

If you're copying data to a tempfile, it will only have complete
buffers (i.e. multiples of 4096 bytes) in it until the final flush
or close.

So I'm imagining something like:

  tfp = open(tempfilename, "w")
  ... lots of tfp.write() ...
  shutil.copyfile(tempfilename, newfilename)

Note above no flush or close of tfp. So the final incomplete I/O
buffer is still in Python's memory; it hasn't been actually written
to the temp file because the buffer has not been filled, and the file
has not been closed.

Anyway, can you show us the relevant bits of code involved?

Cheers,
-- 
Cameron Simpson 

Processes are like potatoes.- NCR device driver manual
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: name lookup failure using metaclasses with unittests

2013-04-12 Thread Ulrich Eckhardt

Am 11.04.2013 10:19, schrieb Steven D'Aprano:

if sys.version >= '3':


Use sys.version_info >= (3,), otherwise your code breaks when upgrading 
to Python 10 and greater. ;^)




The second question that came up was if there is a way to keep a
metaclass defined inside the class or if the only way is to provide it
externally. [...]


Not in general, since the metaclass has to exist independently of the
class.


Thanks for your explanations, they are appreciated.


> The class is an instance of your metaclass. That means that the
> metaclass must exist first, so it can be instantiated when you
> define the class.

I don't like the approach to define the code to post-process a class 
before defining the class. It's a bit like top-posting, it messes up the 
reading order. Since I really intend to post-process the class, it seems 
that metaclasses are simply not the right tool.


At the moment, this leaves me with two options:

1. post-process the class

class X:
pass
# attach constants to clas X
for i in (1, 2, 3):
setattr(X, 'f{}' % i, i)

2. generate code inline

class Y: pass
# generate constants in local (class-)namespace
for i in (1, 2, 3):
locals()['f{}' % i] = i

In both cases, variables (loop variable 'i') are leaked into the 
surrounding namespace, which is kind-of ugly. The second approach also 
seems a bit hackish and I can't use the class-in-definition there, which 
is limiting when you want to attach e.g. constants of type X to X.




Also PEP 3115 "Metaclasses in Python 3000"[2] seems to
consider postprocessing of a class definition as better handled by a
class decorator, which is something I haven't looked at yet.


Generally, class decorators are less brain-melting than metaclasses.


Alas, they also need to be defined before the class, messing with the 
mentioned order of declaration. They can be used to call a class 
function though which then does the necessary postprocessing...


3. post-process the class triggered with decorator

def postprocess_class(cls):
"""invoke postprocess() on the decorated object"""
cls.postprocess()
del cls.postprocess
return cls

@postprocess_class
class Z:
@classfunction
def postprocess(cls):
# attach constants to class
for i in (1, 2, 3):
setattr(cls, 'f{}' % i, i)


I guess I'll stay with variant 1 for now, since it requires the least 
amount of code and the least amount of questions from other developers here.


Thanks everybody!

Uli



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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Ned Deily
In article <6eeabeb2-e6dd-49fc-bd64-8de539651...@googlegroups.com>,
 Rob Schneider  wrote:
> > The file system is Mac OS Extended Journaled (default as out of the box).
> It shows file size 45,056 on both source and target, which is the file size 
> of the flawed target, and is not what Finder shows for source.

Perhaps the source file has an OS X resource fork or other extended 
attribute metadata.  shutil's copy functions won't handle those.  One 
way to see if that is the case is to examine the source file in a 
terminal window with:  ls -l@

$ ls -l@ test.jpg
-rw-r--r--@ 1 nad  staff  40359 Jul 15  2009 test.jpg
   com.apple.FinderInfo32
   com.apple.ResourceFork  899489

-- 
 Ned Deily,
 n...@acm.org

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


Re: shutil.copyfile is incomplete (truncated)

2013-04-12 Thread Chris Angelico
On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider  wrote:
>
>> The close method is defined and flushing and closing a file, so
>>
>> it should not return until that's done.
>>
>>
>>
>> What command are you using to create the temp file?
>>
>>
>
> re command to write the file:
> f=open(fn,'w')
> ... then create HTML text in a string
> f.write(html)
> f.close

Hold it one moment... You're not actually calling close. The file's
still open. Is that a copy/paste problem, or is that your actual code?

In Python, a function call ALWAYS has parentheses after it. Evaluating
a function's name like that returns the function (or method) object,
which you then do nothing with. (You could assign it someplace, for
instance, and call it later.) Try adding empty parens:

f.close()

and see if that solves the problem. Alternatively, look into the
'with' statement and the block syntax that it can give to I/O
operations.

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


Re: USBLock : lock/unlock your computer with a USB key

2013-04-12 Thread Ian Kelly
On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman  wrote:
> On 04/11/2013 04:13 AM, Sven wrote:
>>
>> Yes, I had the idea to add bluetooth too, removes the whole plugging and
>> unplugging spiel. I might start work on that,
>> and if anyone else wants to dive in and help, feel free. I will probably
>> need to refactor the Listener a little, or
>> create a USB and BT listener class.
>
>
> Doesn't BlueTooth have a 30 foot range?  For locking I'd rather be at 10 or
> even 5 feet away.

Pair it with a Google Glass and have it lock after you've stopped
looking at the screen for 30 seconds.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Message passing syntax for objects | OOPv2

2013-04-12 Thread Chris Angelico
On Fri, Apr 12, 2013 at 11:57 AM, Mark Janssen
 wrote:
> Further, I will admit that I am not deeply
> experienced in application or Internet programming

Would you listen to someone who is, by his own admission, not
experienced as a surgeon, and tries to tell you that your liver and
heart would be better placed the other way around?

You may well have some insight that nobody else has yet seen, but you
do yourself no service by trying to argue without first-hand
experience, and lots of it. I'm not going to go to a LISP mailing list
and try to tell them that functional programming is better done with
some different syntax, because I am not an experienced LISPer.
(Dabbled in Scheme, that's about as close as I get. And only dabbled.
And only because GNU LilyPond uses it.) Things are the way they are
because someone's spent decades working with them. Sure, not
everything's perfect... but it takes someone with actual coding
experience and expertise to point out improvements.

Read the python-list and python-tutor archives and listen to people
like Peter Otten and Steven D'Aprano, both of whom have been using the
language for, uhh... 3.5 millenia, probably. (Me? I'm a n00b. Haven't
seriously used Python for even a decade yet, though I think I met it
in the late 90s or early 00s. Got my coding experience on other
languages.) Listen to them when they explain to people why Python is
how it is, and you'll gain a much greater comprehension of what
actually works.

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