An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Today i switched to Python v3.2.3 on my remote web server at HostGator.
My cgi-script which it works at python v2.6.6  now produces theses errors:

-- --
Traceback (most recent call last):
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 171, in execute
r = self._query(query)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 330, in _query
rowcount = self._do_query(q)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File metrites.py, line 211, in module
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) )
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 184, in execute
self.errorhandler(self, exc, value)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py,
 line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1)

Even cursor.execute changes in python v3 ?

What are these errors about?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert comma in number?

2013-03-07 Thread Paul Volkov
2013/3/7 Peter Otten __pete...@web.de:
 Last not least there's the option to employ locale-aware formatting:

 import locale
 locale.setlocale(locale.LC_ALL, en_US.UTF-8)
 'en_US.UTF-8'
 locale.format(%d, 12345, grouping=True)
 '12,345'

 In German usage of . and , is reversed, so:

 locale.setlocale(locale.LC_ALL, de_DE.UTF-8)
 'de_DE.UTF-8'
 locale.format(%d, 12345, grouping=True)
 '12.345'

Does this locale-aware example only work on UNIX?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Roland Koebler
Hi,

 but now iam receiving this error concering except:
 
 ni...@superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py 
   File metrites.py, line 88
 except MySQLdb.Error, e:
 ^
 SyntaxError: invalid syntax
 ni...@superhost.gr [~/www/cgi-bin]# 
 
 which used to work ok in v2.6.6
 
 can you help?
Python 3 introduced some Python 2-incompatible changes.
So, please read: http://docs.python.org/release/3.0.1/whatsnew/3.0.html

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


Re: Insert comma in number?

2013-03-07 Thread Peter Otten
Paul Volkov wrote:

 2013/3/7 Peter Otten __pete...@web.de:
 Last not least there's the option to employ locale-aware formatting:

 import locale
 locale.setlocale(locale.LC_ALL, en_US.UTF-8)
 'en_US.UTF-8'
 locale.format(%d, 12345, grouping=True)
 '12,345'

 In German usage of . and , is reversed, so:

 locale.setlocale(locale.LC_ALL, de_DE.UTF-8)
 'de_DE.UTF-8'
 locale.format(%d, 12345, grouping=True)
 '12.345'
 
 Does this locale-aware example only work on UNIX?

If you have Windows in mind: I don't know what it takes to get multiple 
locales on a Windows system, but for the default locale that you can specify 
with

locale.setlocale(locale.LC_ALL, )

it should work.

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 10:58:13 π.μ. UTC+2, ο χρήστης Roland Koebler έγραψε:
 Hi,
 
 
 
  but now iam receiving this error concering except:
 
  
 
  ni...@superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py 
 
File metrites.py, line 88
 
  except MySQLdb.Error, e:
 
  ^
 
  SyntaxError: invalid syntax
 
  ni...@superhost.gr [~/www/cgi-bin]# 
 
  
 
  which used to work ok in v2.6.6
 
  
 
  can you help?
 
 Python 3 introduced some Python 2-incompatible changes.
 
 So, please read: http://docs.python.org/release/3.0.1/whatsnew/3.0.html
 
 
 
 Roland

I did read about print but i'm interesetd to see and its not mentioned there how

except MySQLdb.Error, e:
print ( Query Error: , sys.exc_info()[1].excepinfo()[2] )

is supposed to be written as in Python v3.x
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Any ideas about the error please?

I can assure you all the statemnt are correct ebcause they work in python v2.6.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Lele Gaifax
Νίκος Γκρ33κ nikos.gr...@gmail.com writes:

 I did read about print but i'm interesetd to see and its not mentioned there 
 how

   except MySQLdb.Error, e:
   print ( Query Error: , sys.exc_info()[1].excepinfo()[2] )

 is supposed to be written as in Python v3.x

Read better:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax
4th (bullet) point.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


iterating over a list as if it were a circular list

2013-03-07 Thread Sven
I was wondering what the best approach for the following might be.

Say you have a list P of points and another list N of other items. You can
always assume that

len(N) = len(P)

Now I would like to iterate over P and place one N at each point. However
if you run out of N I'd like to restart from N[0] and carry on until all
the points have been populated.
So far I've got

for point in points:


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


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Angelico
On Thu, Mar 7, 2013 at 8:23 PM, Sven sven...@gmail.com wrote:
 Now I would like to iterate over P and place one N at each point. However if
 you run out of N I'd like to restart from N[0] and carry on until all the
 points have been populated.

Check out itertools.cycle, it should do what you want.

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


iterating over a list as if it were a circular list

2013-03-07 Thread Sven
Stupid keyboard shortcuts, sent it too early. Apologies


I was wondering what the best approach for the following might be.

Say you have a list P of points and another list N of other items. You can
always assume that

len(N) = len(P)

Now I would like to iterate over P and place one N at each point. However
if you run out of N I'd like to restart from N[0] and carry on until all
the points have been populated.
So far I've got (pseudo code)

i = 0
for point in points:
put N[i] at point
if i  len(N):
i = 0

is this the most pythonic way to accomplish this?

Additionally, what if I wanted to pull a random element from N, but I want
to ensure all elements from N have been used before starting to pick
already chosen random elements again.
So far I thought of duplicating the list and removing the randomly chosen
elements from the list, and when it's empty, re-copying it. But that seems
a little wrong if you know what I mean.

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


Re: Unable to connect to internet URL behind firewall

2013-03-07 Thread Sven
On 6 March 2013 16:28, priyanka.khaman...@gmail.com wrote:

 Hi,

 I am using below two approaches to connect to read the content of internet
 url.
 These two approaches work for me when the internet explorer session is
 open.

 When the internet explorer window is closed, below code gives me 407 error.
 I have also set the HTTP_PROXY environment variables as
 http://proxy-example.com:3128


From experience the environment variable name is in lowercase. Try
http_proxy instead.

Don't ask me why this environment variable is lowercase when most others
aren't.

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 11:22:09 π.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
 Νίκος Γκρ33κ nikos.gr...@gmail.com writes:
 
 
 
  I did read about print but i'm interesetd to see and its not mentioned 
  there how
 
 
 
  except MySQLdb.Error, e:
 
  print ( Query Error: , sys.exc_info()[1].excepinfo()[2] )
 
 
 
  is supposed to be written as in Python v3.x
 
 
 
 Read better:
 
 http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax
 
 4th (bullet) point.
 
 
 
 ciao, lele.
 
 -- 
 
 nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
 
 real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
 
 l...@metapensiero.it  | -- Fortunato Depero, 1929.

please give me the exact link to read, i cant seem to find it although you send 
4th bullet i do not see it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Rui Maciel
rusi wrote:

 Anyone who's used emacs will know this as the bane of FLOSS software
 -- 100 ways of doing something and none perfect -- IOW too much
 spurious choice.


This is a fallacy.  Just because someone claims that there are 100 ways of 
doing something and none perfect, it doesn't mean that restricting choice 
leads to perfection.  It doesn't.  It only leads to getting stuck with a 
poor solution with no possibility of improving your life by switching to a 
better alternative.  

Worse, a complete lack of alternatives leads to a complete lack of 
competition, and therefore the absense of incentives to work on 
improvements.  You know, progress.

Choice is good.  Don't pretend it isn't.  It's one of the reasons we have 
stuff like Python or Ruby nowadays, for example.


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


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Rebert
On Mar 7, 2013 1:24 AM, Sven sven...@gmail.com wrote:

 I was wondering what the best approach for the following might be.

 Say you have a list P of points and another list N of other items. You
can always assume that

 len(N) = len(P)

 Now I would like to iterate over P and place one N at each point. However
if you run out of N I'd like to restart from N[0] and carry on until all
the points have been populated.

Untested due to the late hour:

import itertools

for p, n in itertools.izip(P, itertools.cycle(N)):
# do whatever
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Sven
On 7 March 2013 09:31, Chris Rebert c...@rebertia.com wrote:

 On Mar 7, 2013 1:24 AM, Sven sven...@gmail.com wrote:
 
  I was wondering what the best approach for the following might be.
 
  Say you have a list P of points and another list N of other items. You
 can always assume that
 
  len(N) = len(P)
 
  Now I would like to iterate over P and place one N at each point.
 However if you run out of N I'd like to restart from N[0] and carry on
 until all the points have been populated.

 Untested due to the late hour:

 import itertools

 for p, n in itertools.izip(P, itertools.cycle(N)):
 # do whatever


I knew there was a more sensible way to do it. Thanks.




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


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Rebert
On Mar 7, 2013 1:29 AM, Sven sven...@gmail.com wrote:

 Stupid keyboard shortcuts, sent it too early. Apologies


 I was wondering what the best approach for the following might be.

 Say you have a list P of points and another list N of other items. You
can always assume that

 len(N) = len(P)

 Now I would like to iterate over P and place one N at each point. However
if you run out of N I'd like to restart from N[0] and carry on until all
the points have been populated.
snip
 Additionally, what if I wanted to pull a random element from N, but I
want to ensure all elements from N have been used before starting to pick
already chosen random elements again.
 So far I thought of duplicating the list and removing the randomly chosen
elements from the list, and when it's empty, re-copying it. But that seems
a little wrong if you know what I mean.

Just iterate over the list in order, and random.shuffle() the list each
time you reach the end of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 11:50:42 π.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
 Νίκος Γκρ33κ nikos.gr...@gmail.com writes:
 
 
 
  Τη Πέμπτη, 7 Μαρτίου 2013 11:22:09 π.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
 
  http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax
 
  
 
  4th (bullet) point.
 
 
 
  please give me the exact link to read, i cant seem to find it although
 
  you send 4th bullet i do not see it
 
 
 
 Oh come on Νίκος, the above *is* the *exact* link to read, I even
 
 pointed at the right subparagraph: it contains both a link to the
 
 reference manual for the except keyword, and a link to the PEP that
 
 talks about the change.
 
 
 
 ciao, lele.
 
 -- 
 
 nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
 
 real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
 
 l...@metapensiero.it  | -- Fortunato Depero, 1929.

call me an idiot but is till dont see it:

i;am currently trying this:

except MySQLdb.OperationalError, e:

but give sme an internal server error too :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Lele Gaifax
Νίκος Γκρ33κ nikos.gr...@gmail.com writes:

 Τη Πέμπτη, 7 Μαρτίου 2013 11:22:09 π.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
 http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax
 
 4th (bullet) point.

 please give me the exact link to read, i cant seem to find it although
 you send 4th bullet i do not see it

Oh come on Νίκος, the above *is* the *exact* link to read, I even
pointed at the right subparagraph: it contains both a link to the
reference manual for the except keyword, and a link to the PEP that
talks about the change.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Sven
On 7 March 2013 09:28, Rui Maciel rui.mac...@gmail.com wrote:

 rusi wrote:

  Anyone who's used emacs will know this as the bane of FLOSS software
  -- 100 ways of doing something and none perfect -- IOW too much
  spurious choice.


 This is a fallacy.  Just because someone claims that there are 100 ways of
 doing something and none perfect, it doesn't mean that restricting choice
 leads to perfection.  It doesn't.  It only leads to getting stuck with a
 poor solution with no possibility of improving your life by switching to a
 better alternative.


This thread reminds me of an article I read recently:

http://rubiken.com/blog/2013/02/11/web-dev-a-crazy-world.html

It's mostly a matter of having enough time to evaluate what's best for you.
In the case of RoR vs Django, you will (assuming zero knowledge) need to
learn a language, then a framework. That's quite a time consuming task.
Personally I've opted for Django because I've used Python for years. I've
written some Ruby in the past, but I not enough to make me choose RoR over
Django to get stuff done.

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
This fails also:

except MySQLdb.ProgrammingError, e:

How on earth the exception is suppsoed to be written
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Chris Angelico
On Thu, Mar 7, 2013 at 8:50 PM, Lele Gaifax l...@metapensiero.it wrote:
 Νίκος Γκρ33κ nikos.gr...@gmail.com writes:

 Τη Πέμπτη, 7 Μαρτίου 2013 11:22:09 π.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
 http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax

 4th (bullet) point.

 please give me the exact link to read, i cant seem to find it although
 you send 4th bullet i do not see it

 Oh come on Νίκος, the above *is* the *exact* link to read, I even
 pointed at the right subparagraph: it contains both a link to the
 reference manual for the except keyword, and a link to the PEP that
 talks about the change.

I think it's time to take him up on his offer to call him an idiot :)

Nikos, try 'as'.

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Joel Goldstick
On Thu, Mar 7, 2013 at 5:09 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:

 This fails also:

 except MySQLdb.ProgrammingError, e:

 How on earth the exception is suppsoed to be written


Change from 
excepthttp://docs.python.org/release/3.0.1/reference/compound_stmts.html#except
*exc*, *var* to
excepthttp://docs.python.org/release/3.0.1/reference/compound_stmts.html#except
*exc* ashttp://docs.python.org/release/3.0.1/reference/compound_stmts.html#as
*var*. See *PEP 3110* http://www.python.org/dev/peps/pep-3110.


So change the comma to the word 'as'

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




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 12:19:05 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
 On Thu, Mar 7, 2013 at 8:50 PM, Lele Gaifax l...@metapensiero.it wrote:
 
  Νίκος Γκρ33κ nikos.gr...@gmail.com writes:
 
 
 
  Τη Πέμπτη, 7 Μαρτίου 2013 11:22:09 π.μ. UTC+2, ο χρήστης Lele Gaifax 
  έγραψε:
 
  http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax
 
 
 
  4th (bullet) point.
 
 
 
  please give me the exact link to read, i cant seem to find it although
 
  you send 4th bullet i do not see it
 
 
 
  Oh come on Νίκος, the above *is* the *exact* link to read, I even
 
  pointed at the right subparagraph: it contains both a link to the
 
  reference manual for the except keyword, and a link to the PEP that
 
  talks about the change.
 
 
 
 I think it's time to take him up on his offer to call him an idiot :)
 
 
 
 Nikos, try 'as'.
 
 
 
 ChrisA

Thank you all the trick was to replace the comma with the 'as'

script is almost ready for Python v3.2.3 now!

ima just receivign this error:

-- --
Traceback (most recent call last):
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 171, in execute
r = self._query(query)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 330, in _query
rowcount = self._do_query(q)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File metrites.py, line 212, in module
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) )
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py,
 line 184, in execute
self.errorhandler(self, exc, value)
  File 
/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py,
 line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1)

Tou cna see it more clearly at my website http://superhost.gr
-- 
http://mail.python.org/mailman/listinfo/python-list


3.3.1 release date?

2013-03-07 Thread sferencik
Hi,

When is the 3.3.1 final due? I have found this 
[http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem up to 
date. Is there a better source of this info?

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


Re: Interesting list() un-optimization

2013-03-07 Thread Wolfgang Maier
Tim Chase python.list at tim.thechases.com writes:
 
 On 2013-03-06 22:20, Roy Smith wrote:
  I stumbled upon an interesting bit of trivia concerning lists and
  list comprehensions today.
 
 A little testing
 shows that this can be rewritten as
 
   my_objects = list(iter(my_query_set))
 
 which seems to then skip the costly __len__ call.  Performance geeks
 are welcome to time it against the list-comprehension version 
 
 class Foo(object):
 def __init__(self):
 self.items = range(10)
 def __iter__(self):
 return iter(self.items)
 def __len__(self):
 print Calling costly __len__
 return len(self.items)
 

Well, it skips the costly len() call because your iter(Foo()) returns
iter(range()) under the hood and list() uses that object's __len__() method. In
most cases, such a workaround will not be feasible. Why should iter(QuerySet())
have a faster __len__() method defined than QuerySet() itself. Most likely,
iter(QuerySet()) just returns self anyway?
Best,
Wolfgang



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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 11:06:27 π.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ έγραψε:
 Any ideas about the error please?
 
 
 
 I can assure you all the statemnt are correct ebcause they work in python 
 v2.6.6

can someone help this issue so my webiste will get back on working plz?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Michael Ross
On Thu, 07 Mar 2013 12:27:03 +0100, Νίκος Γκρ33κ nikos.gr...@gmail.com  
wrote:


Τη Πέμπτη, 7 Μαρτίου 2013 11:06:27 π.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ  
έγραψε:

Any ideas about the error please?



I can assure you all the statemnt are correct ebcause they work in  
python v2.6.6


can someone help this issue so my webiste will get back on working plz?


MySQLdb is python 2 only.
MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently  
supported. Python-3.0 will be supported in a future release.


Maybe try this one:
https://pypi.python.org/pypi/mysql-connector-python/1.0.9

Alternatively,
forget about subprocess.check_output,
call your metrites.py with os.system('python metrites.py some-temp-file')
and have it write its output to some-temp-file,
and read some-temp-file back into your template?

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]

Why this line that worked in v2.6 give sme an error in v3.2.3

Traceback (most recent call last):
  File files.py, line 14, in lt;modulegt;
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
  File /opt/python3/lib/python3.2/os.py, line 450, in __getitem__
value = self._data[self.encodekey(key)]
KeyError: b'REMOTE_ADDR'

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


Re: 3.3.1 release date?

2013-03-07 Thread Terry Reedy

On 3/7/2013 6:02 AM, sferen...@gmail.com wrote:

Hi,

When is the 3.3.1 final due? I have found this
[http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem
up to date. Is there a better source of this info?


No. There are lingering issues that were expected to be resolved 
already, but have not been.


--
Terry Jan Reedy

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


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Νίκος Γκρ33κ
An these kind of errors iam receiving to please:

Original exception was:
Traceback (most recent call last):
  File pelatologio.py, line 230, in module
''') % (clients, hits, money)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 102-108: 
ordinal not in range(128)

in python v2.6.6 this code works and now i'am using:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting-embedding some html data at the end of a .py file

2013-03-07 Thread Chris Angelico
On Thu, Mar 7, 2013 at 11:06 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 An these kind of errors iam receiving to please:

Part of being a computer programmer is learning to solve problems.
Dumping piles of problems onto a list like this isn't the best way to
do this. Either pay someone to do the work (there are plenty of web
sites that will help you find freelance programmers), or learn to do
it yourself. Coming to a list like this should be done respectfully -
knowing that you're asking people to devote dev hours for no return -
and preferably in accordance with:

http://www.catb.org/esr/faqs/smart-questions.html

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


Re: Creating an object that can track when its attributes are modified

2013-03-07 Thread Schneider

Hi,
maybe you could do this by a decorator on the setattr method. It should 
look more or less

like your implementation, but in my eyes it's a cleaner and can be reused.

Further, I would use a stack for each attribute, so that you can restore 
all previous values.


bg,
Johannes

On 03/06/2013 05:07 PM, Ben Sizer wrote:

I am trying to make an object that can track when its attributes have been 
assigned new values, and which can rollback to previous values where necessary. 
I have the following code which I believe works, but would like to know if 
there are simpler ways to achieve this goal, or if there are any bugs I haven't 
seen yet.


class ChangeTrackingObject(object):
 def __init__(self):
 self.clean()

 def clean(self):
 Mark all attributes as unmodified.
 object.__setattr__(self, '_dirty_attributes', dict())

 def dirty_vals(self):
 Returns all dirty values.
 return dict( [ (k,v) for k,v in self.__dict__.iteritems() if k in 
self._dirty_attributes]  )

 def get_changes_and_clean(self):
 Helper that collects all the changes and returns them, cleaning the dirty flags at 
the same time.
 changes = self.dirty_vals()
 self.clean()
 return changes

 def rollback(self):
 Reset attributes to their previous values.
 for k,v in self._dirty_attributes.iteritems():
 object.__setattr__(self, k, v)
 self.clean()

 def __setattr__(self, key, value):
 # If the first modification to this attribute, store the old value
 if key not in self._dirty_attributes:
 if key in self.__dict__:
 self._dirty_attributes[key] = object.__getattribute__(self, 
key)
 else:
 self._dirty_attributes[key] = None
 # Set the new value
 object.__setattr__(self, key, value)


I am aware that adding a new attribute and then calling rollback() leaves the 
new attribute in place with a None value - maybe I can use a special DeleteMe 
marker object in the _dirty_attributes dict along with a loop that calls 
delattr on any attribute that has that value after a rollback.

I also believe that this won't catch modification to existing attributes as 
opposed to assignments: eg. if one of the attributes is a list and I append to 
it, this system won't notice. Is that something I can rectify easily?

Any other comments or suggestions?

Thanks,


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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 1:51:42 μ.μ. UTC+2, ο χρήστης Michael Ross έγραψε:
 On Thu, 07 Mar 2013 12:27:03 +0100, Νίκος Γκρ33κ nikos.gr...@gmail.com  
 
 wrote:
 
 
 
  Τη Πέμπτη, 7 Μαρτίου 2013 11:06:27 π.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ  
 
  έγραψε:
 
  Any ideas about the error please?
 
 
 
 
 
 
 
  I can assure you all the statemnt are correct ebcause they work in  
 
  python v2.6.6
 
 
 
  can someone help this issue so my webiste will get back on working plz?
 
 
 
 MySQLdb is python 2 only.
 
 MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently  
 
 supported. Python-3.0 will be supported in a future release.
 
 
 
 Maybe try this one:
 
 https://pypi.python.org/pypi/mysql-connector-python/1.0.9
 
 
 
 Alternatively,
 
 forget about subprocess.check_output,
 
 call your metrites.py with os.system('python metrites.py some-temp-file')
 
 and have it write its output to some-temp-file,
 
 and read some-temp-file back into your template?

Yes its better for me to give upon python3 for the moment being, because all 
that hassle was for makeing the subprocess command run.

Now i just followed your advice and tried:

elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py 
/data/files/htmltemp')

but produced error tells me that:

template undefined, htmldata = -1, counter = ' centera 
href=mailto:supp...@superhost.gr; ...st.gr/?show=statsfont color=cyan 0 
/td\n\t\t '

whay htmldata reeturn the value '-1' when os.sytem is executed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Michael Ross
On Thu, 07 Mar 2013 13:25:58 +0100, Νίκος Γκρ33κ nikos.gr...@gmail.com  
wrote:


Τη Πέμπτη, 7 Μαρτίου 2013 1:51:42 μ.μ. UTC+2, ο χρήστης Michael Ross  
έγραψε:

On Thu, 07 Mar 2013 12:27:03 +0100, Νίκος Γκρ33κ nikos.gr...@gmail.com

wrote:



 Τη Πέμπτη, 7 Μαρτίου 2013 11:06:27 π.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ

 έγραψε:

 Any ideas about the error please?







 I can assure you all the statemnt are correct ebcause they work in

 python v2.6.6



 can someone help this issue so my webiste will get back on working  
plz?




MySQLdb is python 2 only.

MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently

supported. Python-3.0 will be supported in a future release.



Maybe try this one:

https://pypi.python.org/pypi/mysql-connector-python/1.0.9



Alternatively,

forget about subprocess.check_output,

call your metrites.py with os.system('python metrites.py  
some-temp-file')


and have it write its output to some-temp-file,

and read some-temp-file back into your template?


Yes its better for me to give upon python3 for the moment being, because  
all that hassle was for makeing the subprocess command run.


Now i just followed your advice and tried:

elif htmlpage.endswith('.py'):
		htmldata = os.system('/usr/bin/python ./metrites.py  
/data/files/htmltemp')


but produced error tells me that:

template undefined, htmldata = -1, counter = ' centera  
href=mailto:supp...@superhost.gr; ...st.gr/?show=statsfont  
color=cyan 0 /td\n\t\t '


whay htmldata reeturn the value '-1' when os.sytem is executed?


Because
On Unix, the return value is the exit status of the process encoded in  
the format specified for wait().


It's in the documentation for os.system.
Which you should have read before asking here.

You may not intend it like that,
but if you ask any and all errors here, you effectively ask the list to  
develop the software for you.


Seriously this is beyond the scope of volunteer help for a commercial site.
I'm bailing out.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unhelpful traceback

2013-03-07 Thread Dave Angel

On 03/07/2013 01:33 AM, John Nagle wrote:

Here's a traceback that's not helping:



A bit more context would be helpful.  Starting with Python version.


Traceback (most recent call last):
   File InfoCompaniesHouse.py, line 255, in module
 main()
   File InfoCompaniesHouse.py, line 251, in main
 loader.dofile(infile)   # load this file
   File InfoCompaniesHouse.py, line 213, in dofile
 self.dofilezip(infilename)  # do ZIP file
   File InfoCompaniesHouse.py, line 198, in dofilezip
 self.dofilecsv(infile, infd)# as a CSV file
   File InfoCompaniesHouse.py, line 182, in dofilecsv
 for fields in reader :  # read entire
CSV file
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in
position 14: ordinal not in range(128)

This is wierd, becuase for fields in reader isn't directly
doing a decode. That's further down somewhere, and the backtrace
didn't tell me where.

The program is converting some .CSV files that come packaged in .ZIP
files.  The files are big, so rather than expanding them, they're
read directly from the ZIP files and processed through the ZIP
and CSV modules.

Here's the code that's causing the error above:





 decoder = codecs.getreader('utf-8')
 with decoder(infdraw,errors=replace) as infd :
 with codecs.open(outfilename, encoding='utf-8', mode='w') as
outfd :
 headerline = infd.readline()
 self.doheaderline(headerline)
 reader = csv.reader(infd, delimiter=',', quotechar='')
 for fields in reader :
 pass

Normally, the pass is a call to something that
uses the data, but for test purposes, I put a pass in there.  It still
fails.   With that pass, nothing is ever written to the
output file, and no encoding should be taking place.

infdraw is a stream from the zip module, create like this:

 with inzip.open(zipelt.filename,r) as infd :


You probably need a 'rb' rather than 'r', since the file is not ASCII.


 self.dofilecsv(infile, infd)

This works for data records that are pure ASCII, but as soon as some
non-ASCII character comes through, it fails.

Where is the error being generated?  I'm not seeing any place
where there's a conversion to ASCII.  Not even a print.

John Nagle






If that isn't enough, then please give the whole context, such as where 
zipelt and filename came from.  And don't forget to specify Python 
version.  Version 3.x treats nonbinary files very differently than 2.x


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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Please tell me at least if i ahve any syntax error in this line:

htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

please man its essential for my website to work otherwise 3 scripts i wrote 
would not be able to produce proper html output that then i need to append a 
string after them. her si what i want to do:

if htmlpage.endswith('.html'):
f = open( /home/nikos/www/ + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py 
/data/files/htmltemp')


counter = ''' centera href=mailto:supp...@superhost.gr; img 
src=/data/images/mail.png /a
  centertable border=2 cellpadding=2 bgcolor=black
tdfont color=limeΑριθμός Επισκεπτών/td
tda 
href=http://superhost.gr/?show=stats;font color=cyan %d /td
  ''' % data[0]


template = htmldata + counter
print( template )

==

Please just that i like to do it myself ut i cant, i wont ask anyhting else.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Roy Smith
In article mailman.2993.1362648214.2939.python-l...@python.org,
 Sven sven...@gmail.com wrote:

 I was wondering what the best approach for the following might be.
 
 Say you have a list P of points and another list N of other items. You can
 always assume that
 
 len(N) = len(P)
 
 Now I would like to iterate over P and place one N at each point. However
 if you run out of N I'd like to restart from N[0] and carry on until all
 the points have been populated.
 So far I've got
 
 for point in points:

I'm not completely following what you're trying to do, but I think what 
you're looking for is some combination of zip() and itertools.cycle().

pairs = zip(P, cycle(N))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 12:22 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 Please tell me at least if i ahve any syntax error in this line:

 htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

 please man its essential for my website to work otherwise 3 scripts i wrote 
 would not be able to produce proper html output

Yes, there is. The variable name at the beginning is wrong. To
understand why, look at the documentation for os.system().

If it's essential for your web site, why not pay someone to do the work for you?

You want free support AND you're not willing to put effort into your
questions. That's a bad combination. The sloppiness of your writing,
coupled with a clear lack of preliminary research (eg checking the
docs), suggests that you do not value the end result; you expect
someone else to do everything, to wave a magic wand and voila, your
web site works. That isn't how the world works.

Quoting from http://www.catb.org/esr/faqs/smart-questions.html
 == Before you ask ==
 Prepare your question. Think it through. Hasty-sounding questions get
 hasty answers, or none at all. The more you do to demonstrate that having
 put thought and effort into solving your problem before seeking help, the
 more likely you are to actually get help.
...
 == Write in clear, grammatical, correctly-spelled language ==
 ... If you can't be bothered to do that, we can't be bothered to pay 
 attention.
 Spend the extra effort to polish your language. It doesn't have to be stiff or
 formal - in fact, hacker culture values informal, slangy and humorous
 language used with precision. But it has to be precise; there has to be
 some indication that you're thinking and paying attention.
 ... if you write like a semi-literate boob you will very likely be ignored.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
But iam tryign dayd for this i even tryign to chnage my 3 script to python 
v3.2.3 just to get subprocess up and running

all the above fail:

htmldata = os.system(python metrites.py '/data/files/htmltemp')

How can i tell system to send metritis.py's output to a temporary file called 
htmltemp so in the next step i can do what iam trying 3 days now to do:

template = htmldata + counter

os.system is very vague while i need specific help with this.
if you provide me a link that describes my case of things i';; for sure read it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 12:56 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 But iam tryign dayd for this i even tryign to chnage my 3 script to python 
 v3.2.3 just to get subprocess up and running

 all the above fail:

 htmldata = os.system(python metrites.py '/data/files/htmltemp')

 How can i tell system to send metritis.py's output to a temporary file called 
 htmltemp so in the next step i can do what iam trying 3 days now to do:

 template = htmldata + counter

 os.system is very vague while i need specific help with this.
 if you provide me a link that describes my case of things i';; for sure read 
 it.

You are panicking about specific problems. Take a deep breath, take a
step back, and look at what's going on. If you've really been trying
for three days to make this work, it won't cost you much more to spend
three minutes polishing your email before you send it... or those same
three minutes reading the docs and finding what you want.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 4:01:13 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:

 You are panicking about specific problems. Take a deep breath, take a
 
 step back, and look at what's going on. If you've really been trying
 
 for three days to make this work, it won't cost you much more to spend
 
 three minutes polishing your email before you send it... or those same
 
 three minutes reading the docs and finding what you want.

Iam willing to read some document that describe what iam dealing with, please 
provid eme a link and aill read it

I think its an OS issue and not statment issue.

iam starting to hink that maybe

python metritis.py  /data/files/htmltemp

might work. i will try this now as we speak.lets hope for God;s sake it will 
work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
I made some progress!!! Now the htmldata's value its not -1 but 256!!!

look the error after trying this:
htmldata = os.system(python metrites.py  '/data/private/htmltemp')


template undefined, htmldata = 256, counter = ' centera 
href=mailto:supp...@superhost.gr; ...st.gr/?show=statsfont color=cyan 0 
/td\n\t\t '
type 'exceptions.TypeError': unsupported operand type(s) for +: 'int' and 
'str' 
  args = (unsupported operand type(s) for +: 'int' and 'str',) 
  message = unsupported operand type(s) for +: 'int' and 'str'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 1:11 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 Τη Πέμπτη, 7 Μαρτίου 2013 4:01:13 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:

 You are panicking about specific problems. Take a deep breath, take a

 step back, and look at what's going on. If you've really been trying

 for three days to make this work, it won't cost you much more to spend

 three minutes polishing your email before you send it... or those same

 three minutes reading the docs and finding what you want.

 Iam willing to read some document that describe what iam dealing with, please 
 provid eme a link and aill read it

http://www.google.com/

 I think its an OS issue and not statment issue.

I think it's a pebkac issue.

 iam starting to hink that maybe

 python metritis.py  /data/files/htmltemp

 might work. i will try this now as we speak.lets hope for God;s sake it will 
 work!

Tip: Next time, try it first, THEN post. This is not IRC. You don't
need to tell us that you're trying, and that you're panicking still
further.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 1:13 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 I made some progress!!! Now the htmldata's value its not -1 but 256!!!

 look the error after trying this:
 htmldata = os.system(python metrites.py  '/data/private/htmltemp')

Go check the docs for os.system() and understand why 'htmldata' is the
wrong name for its return value.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Docs doesn't explain that i just take looked at 
http://docs.python.org/2/library/os.html#os.system

I see that the return value of os.system its an indicator to as if the command 
inside os.system() returned successfully.

So i guess ill be needing somethign like this:

htmltemp = '/home/nikos/www/data/private/htmltemp'

if htmlpage.endswith('.html'):
f = open( /home/nikos/www/ + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
os.system( 'python metrites.py  %s' ) % htmltemp
f = open( htmltemp )
htmldata = f.read()

template = htmldata + counter
==

which i just tried and now iam receiving this:

type 'exceptions.TypeError': unsupported operand type(s) for %: 'int' and 
'str' 

I'am very close to the solution now i cna feel it but please help a bit!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 1:34 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 os.system( 'python metrites.py  %s' ) % htmltemp

 type 'exceptions.TypeError': unsupported operand type(s) for %: 'int' and 
 'str'

Simple parenthesis problem. Take a careful look at the line mentioned
in the exception traceback (which you didn't share with us, but
fortunately the error's pretty obvious) and see if you can find the
problem.

Hint: htmltemp is the str mentioned in the error.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 4:37:31 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
 On Fri, Mar 8, 2013 at 1:34 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 
  os.system( 'python metrites.py  %s' ) % htmltemp
 
 
 
  type 'exceptions.TypeError': unsupported operand type(s) for %: 'int' and 
  'str'
 
 
 
 Simple parenthesis problem. Take a careful look at the line mentioned
 
 in the exception traceback (which you didn't share with us, but
 
 fortunately the error's pretty obvious) and see if you can find the
 
 problem.

 Hint: htmltemp is the str mentioned in the error.


 /home/nikos/public_html/cgi-bin/metrites.py in ()
  220 htmldata = f.read()
  221 elif htmlpage.endswith('.py'):
  222 os.system( 'python metrites.py  %s' ) % htmltemp
  223 f = open( htmltemp )
  224 htmldata = f.read()
os = module 'os' from '/usr/lib64/python2.6/os.pyc', os.system = built-in 
function system, htmltemp = '/home/nikos/www/data/private/htmltemp'
type 'exceptions.TypeError': unsupported operand type(s) for %: 'int' and 
'str' 
  args = (unsupported operand type(s) for %: 'int' and 'str',) 
  message = unsupported operand type(s) for %: 'int' and 'str'

Τhis is the complete traceback iam reading it and reading it all over but i 
just dont *see* what it tries to tell me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 1:44 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
  /home/nikos/public_html/cgi-bin/metrites.py in ()
   220 htmldata = f.read()
   221 elif htmlpage.endswith('.py'):
   222 os.system( 'python metrites.py  %s' ) % htmltemp
   223 f = open( htmltemp )
   224 htmldata = f.read()
 os = module 'os' from '/usr/lib64/python2.6/os.pyc', os.system = built-in 
 function system, htmltemp = '/home/nikos/www/data/private/htmltemp'
 type 'exceptions.TypeError': unsupported operand type(s) for %: 'int' and 
 'str'
   args = (unsupported operand type(s) for %: 'int' and 'str',)
   message = unsupported operand type(s) for %: 'int' and 'str'

 Τhis is the complete traceback iam reading it and reading it all over but i 
 just dont *see* what it tries to tell me.

Try to get the default output from an exception, it's a lot more
useful. In any case, line 222 is the one being highlighted; you get a
couple of lines of context, but the middle one is where the error is.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
os.system( 'python metrites.py  htmltemp' )
f = open( htmltemp )
htmldata = f.read() 

gives:

f undefined, builtin open = built-in function open, temp = 
'/home/nikos/www/data/private/htmltemp'
type 'exceptions.IOError': [Errno 2] ��� ��� �� �� � �: 
'/home/nikos/www/data/private/htmltemp' 
  args = (2, '\xc4\xe5\xed \xf5\xf0\xdc\xf1\xf7\xe5\xe9 
\xf4\xdd\xf4\xef\xe9\xef \xe1\xf1\xf7\xe5\xdf\xef \xde 
\xea\xe1\xf4\xdc\xeb\xef\xe3\xef\xf2') 
  errno = 2 
  filename = '/home/nikos/www/data/private/htmltemp' 
  message = '' 
  strerror = '\xc4\xe5\xed \xf5\xf0\xdc\xf1\xf7\xe5\xe9 
\xf4\xdd\xf4\xef\xe9\xef \xe1\xf1\xf7\xe5\xdf\xef \xde 
\xea\xe1\xf4\xdc\xeb\xef\xe3\xef\xf2'

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Why f gives back an error and doesnt open the filename that i give it as 
anvariable successfully?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 4:50:34 μ.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ έγραψε:
 os.system( 'python metrites.py  htmltemp' )

That is wrong now i realize, it takes htmltemp as the filename where what i 
need is to take it htmltemp's varibales value.

Switching back to:

os.system( 'python metrites.py  %s' ) % htmltemp
f = open( htmltemp )
htmldata = f.read() 

but still donse see what iam doing wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 2:01 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 os.system( 'python metrites.py  %s' ) % htmltemp

Manually step through what this line should do. Follow the exact same
rules Python will follow in evaluating this expression.

http://docs.python.org/2/reference/expressions.html#operator-precedence
http://docs.python.org/3/reference/expressions.html#operator-precedence

As you'll see from footnote 8 or 5 (depending on which version of the
docs), your percent operator is the same one listed in the table as a
division operator.

Now. Go through that expression, step by step. Walk through everything
the Python interpreter does. Figure out exactly what happens first,
second, third. Figure out when your percent operator gets handled.
Then you'll know what's wrong with that line of code.

You'll also gain a very useful understanding of Python, and more
generally of the way most high level languages parse expressions.

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


Python source to C++ and/or Java

2013-03-07 Thread Jabba Laci
Hi,

As a university project, I would like to work on an automated
converter that transforms a Python source code to C++ or Java (not yet
decided but I would vote on Java since it seems less complicated).
Do you know if it's already done? What other similar projects are you aware of?

And most importantly: where could I start this project? Could you give
some ideas/tips?

The converter doesn't have to recognize everything. First we want to
build a simple prototype.

Thanks,

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


Re: Python source to C++ and/or Java

2013-03-07 Thread Alec Taylor
Saw a talk at a Python usergroup today which talked about: Ply

http://www.dabeaz.com/ply/

But you're probably looking for Cython. Python can run of the JRE
e.g.: see Jython.

There was also another one that you can use to build C extensions
with, it was MP... something

On Fri, Mar 8, 2013 at 2:19 AM, Jabba Laci jabba.l...@gmail.com wrote:
 Hi,

 As a university project, I would like to work on an automated
 converter that transforms a Python source code to C++ or Java (not yet
 decided but I would vote on Java since it seems less complicated).
 Do you know if it's already done? What other similar projects are you aware 
 of?

 And most importantly: where could I start this project? Could you give
 some ideas/tips?

 The converter doesn't have to recognize everything. First we want to
 build a simple prototype.

 Thanks,

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 5:13:24 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
 On Fri, Mar 8, 2013 at 2:01 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 
  os.system( 'python metrites.py  %s' ) % htmltemp
 
 
 
 Manually step through what this line should do. Follow the exact same
 
 rules Python will follow in evaluating this expression.
 
 
 
 http://docs.python.org/2/reference/expressions.html#operator-precedence
 
 http://docs.python.org/3/reference/expressions.html#operator-precedence
 
 
 
 As you'll see from footnote 8 or 5 (depending on which version of the
 
 docs), your percent operator is the same one listed in the table as a
 
 division operator.
 
 
 
 Now. Go through that expression, step by step. Walk through everything
 
 the Python interpreter does. Figure out exactly what happens first,
 
 second, third. Figure out when your percent operator gets handled.
 
 Then you'll know what's wrong with that line of code.
 
 
 
 You'll also gain a very useful understanding of Python, and more
 
 generally of the way most high level languages parse expressions.
 
 
 
 ChrisA

I'am sorry to say i cant figure this out :(
please enlight me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python source to C++ and/or Java

2013-03-07 Thread Peter Otten
Jabba Laci wrote:

 As a university project, I would like to work on an automated
 converter that transforms a Python source code to C++ or Java (not yet
 decided but I would vote on Java since it seems less complicated).
 Do you know if it's already done? What other similar projects are you
 aware of?

https://pypi.python.org/pypi/Shed Skin/


An Optimizing (restricted) Python-to-C++ Compiler
Shed Skin is an experimental (restricted) Python-to-C++ compiler. It accepts 
pure but implicitly statically typed Python (2.4-2.6) programs and generates 
optimized C++ code. [...]


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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 2:26 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 Τη Πέμπτη, 7 Μαρτίου 2013 5:13:24 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
 On Fri, Mar 8, 2013 at 2:01 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:

  os.system( 'python metrites.py  %s' ) % htmltemp



 Manually step through what this line should do. Follow the exact same

 rules Python will follow in evaluating this expression.



 http://docs.python.org/2/reference/expressions.html#operator-precedence

 http://docs.python.org/3/reference/expressions.html#operator-precedence



 As you'll see from footnote 8 or 5 (depending on which version of the

 docs), your percent operator is the same one listed in the table as a

 division operator.



 Now. Go through that expression, step by step. Walk through everything

 the Python interpreter does. Figure out exactly what happens first,

 second, third. Figure out when your percent operator gets handled.

 Then you'll know what's wrong with that line of code.



 You'll also gain a very useful understanding of Python, and more

 generally of the way most high level languages parse expressions.



 ChrisA

 I'am sorry to say i cant figure this out :(
 please enlight me.

You can figure it out, but it will take some effort. I will not
enlighten you further. The documentation is all there; the answers are
available.

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread John Gordon
In c2a09443-3c74-477b-af9f-a6f3473eb...@googlegroups.com 
=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= nikos.gr...@gmail.com writes:

 Switching back to:

   os.system( 'python metrites.py  %s' ) % htmltemp
   f =3D open( htmltemp )
   htmldata =3D f.read()=09

 but still donse see what iam doing wrong.

You have the close-parentheses in the wrong place.  The line should be:

os.system( 'python metrites.py  %s' % htmltemp )

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

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 5:33:10 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:

 You can figure it out, but it will take some effort. I will not
 
 enlighten you further. The documentation is all there; the answers are
 
 available.

I found it! I have placed 'htmltemp' within the os.system() call. Otherwise, 
os.system() returns a return value (int) which python then tries to concatenate 
with htmltemp (string).

os.system( 'python metrites.py  %s' % htmltemp )

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


Re: Interesting list() un-optimization

2013-03-07 Thread Ian Kelly
On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier
wolfgang.ma...@biologie.uni-freiburg.de wrote:
 Well, it skips the costly len() call because your iter(Foo()) returns
 iter(range()) under the hood and list() uses that object's __len__() method.

Iterators do not generally have __len__ methods.

 len(iter(range(10)))
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: object of type 'range_iterator' has no len()

 In
 most cases, such a workaround will not be feasible. Why should 
 iter(QuerySet())
 have a faster __len__() method defined than QuerySet() itself.

iter(QuerySet()) should not have any __len__ method defined at all,
which is why the optimization would be skipped.

 Most likely,
 iter(QuerySet()) just returns self anyway?

But on this point, you are correct.  The mongoengine QuerySet.__iter__
method is defined as:

def __iter__(self):
self.rewind()
return self

This is unfortunate design.  Not only does it mean that the iterator's
__len__ method cannot be trusted (what should the __len__ of a
partially exhausted iterator return?), but it also means that requesting
an iterator over the QuerySet will also silently invalidate any
existing iterators.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 5:55:58 μ.μ. UTC+2, ο χρήστης John Gordon έγραψε:
 In c2a09443-3c74-477b-af9f-a6f3473eb...@googlegroups.com 
 =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= nikos.gr...@gmail.com writes:
 
 
 
  Switching back to:
 
 
 
  os.system( 'python metrites.py  %s' ) % htmltemp
 
  f =3D open( htmltemp )
 
  htmldata =3D f.read()=09
 
 
 
  but still donse see what iam doing wrong.
 
 
 
 You have the close-parentheses in the wrong place.  The line should be:
 
 
 
 os.system( 'python metrites.py  %s' % htmltemp )
 
 
 
 -- 
 
 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

Yes thank you, i found it myself and moment later i also saw your post!
I'am very excites i discoverd it myself!

Now instead of receiving proper html output i receive this:

Go to http://superhost.gr please and click the 1st image you see on the top.
Instead for the pelatologio.py html output to appear + counter string

i see weird formatting, if you want please take a look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: listbox binding..what is the current selection?

2013-03-07 Thread William Ray Wing
On Mar 6, 2013, at 11:38 PM, Rex Macey xer0...@gmail.com wrote:

 Thanks.  I have spent time with the docs, at least with the Python v3.3 and 
 tkinter v8.5 (pdf).  I wish they had more examples. My approach is to browse 
 the docs, try a program, fail, read the docs, try again.  When I can't figure 
 it out, I post.  I appreciate the help.   
 
 

With apologies for jumping into the middle of this discussion, but I've found 
the most helpful tkinter v8.5 docs to be the set at New Mexico tech:

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

Seem quite complete and in particular, starting at section 28, they are quite 
detailed in their explanation of the ttk themed widgets.

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


Re: Config ConfigParser

2013-03-07 Thread Neil Cerutti
On 2013-03-06, Chris Angelico ros...@gmail.com wrote:
 On Wed, Mar 6, 2013 at 2:31 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 What configuration settings does your podcast catcher software
 need? What makes you think it needs any? Don't over-engineer
 your application from the start. Begin with the simplest thing
 that works, and go from there.

 Agreed. The way I generally do these things is to simply gather the
 config entries into a block of literal assignments at the top of the
 program:

 host = ftp
 port = 21
 proxy = 192.168.0.3:81
 user = transfers
 password = secret

I find it useful to stuff my config info in a class object; It is
prettier than ALLCAPS, and also makes it simple to create and use
new configurations without erasing or commenting out the old one.

class Config:
  host = ftp
  port = 21
  proxy = 192.168.0.3:81
  user = transfers
  password = secret

How much to engineer stuff is up to you.

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


Cloudicy.com - New Social Network

2013-03-07 Thread Tufan Cakiroglu
Hi. I am owner of www.cloudicy.com 

Cloudicy.com is a new cloud dictionary and website. Its a kind of Social 
Network. Users can create topics on website and post informations, suggestions, 
comments and critiques for posts.

I need users (for manage posts and testing) and PHP developers.

Please contact with me 
Tufan Çakıroğlu 
tufancakiro...@cloudicy.com
www.cloudicy.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Christian Heimes
Am 07.03.2013 17:00, schrieb Ian Kelly:
 On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier
 wolfgang.ma...@biologie.uni-freiburg.de wrote:
 Well, it skips the costly len() call because your iter(Foo()) returns
 iter(range()) under the hood and list() uses that object's __len__() method.
 
 Iterators do not generally have __len__ methods.
 
 len(iter(range(10)))
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: object of type 'range_iterator' has no len()

But iterators have a length hint method that are used for some
optimizations and preallocations, too.

 i = iter(range(10))
 i.__length_hint__()
10

See http://www.python.org/dev/peps/pep-0424/

Christian

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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
I have fixed this!
Still ahve allok and you will see that in both of my images they appear in the 
firstpage of superhost.gr

the output of .py files appear fine except of that ehen a visitor click on my 
first 2 image links he also sees as first line this:

print ( Content-type: text/html; charset=utf-8\n )

this is because the above code is a header and its contained to every cgi .py 
file that i generate html ouput from via os.system()

Can this be somehow eliminated?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Rick Johnson
On Thursday, March 7, 2013 3:28:41 AM UTC-6, Rui Maciel wrote:
 rusi wrote:
 
  Anyone who's used emacs will know this as the bane of FLOSS software
  -- 100 ways of doing something and none perfect -- IOW too much
  spurious choice.
 
 This is a fallacy.  Just because someone claims that there are 100 ways of 
 doing something and none perfect, it doesn't mean that restricting choice 
 leads to perfection.  It doesn't.  It only leads to getting stuck with a 
 poor solution with no possibility of improving your life by switching to a 
 better alternative.  

Not true. The one solution is only poor when the dev team of that one 
solution become resistant to change. But i don't think anybody would agree 
that a *single* solution could exist for ALL problems (at least not in the 
early stages of defining a problem domain'), although a *single* solution 
could exist for MOST problems.

 Worse, a complete lack of alternatives leads to a complete lack of 
 competition, and therefore the absense of incentives to work on 
 improvements.  You know, progress.

Wrong again. You don't need 10 versions of the same software to maintain 
evolution. Your premise is that competition between multiple versions of, what 
is basically the same exact software with TINY difference, creates evolution; 
WRONG!; competition cannot exist without IDEAS, and it is the presence of 
conflicting IDEAS that create evolution in software development, NOT 
fragmentation. 

Fragmenting the pool of great software developers into zeoltry sects is 
slowing evolution. What you do need is a bare minimum of projects that are 
perpetually open to outside ideas and constant evolution. You goal should be to 
work towards a single monolithic solution. But you must also keep in mind that 
the single solution must continue to evolve.

 Choice is good.  Don't pretend it isn't.  It's one of the reasons we have 
 stuff like Python or Ruby nowadays, for example.

Python and Ruby should both be superseded by a language that takes the best 
from both languages. Python and Ruby are so much alike in so many ways it's 
really silly. I think the main split point at this time is the PythonZen vs 
TIMTOWDI. 

Sure there are some glaring differences in Ruby vs Python methodology, but at 
the end of the day, An iterator is an iterator, a class is a class, a sequence 
is a sequence, a mapping is a mapping, a conditional is a conditional, a 
variable is a variable. Python has list comprehensions and Ruby has 
Array.[select|collect]. 

But let's investigate a much better example where multiplicity has fragmented a 
problem domain into OBLIVION, and that domain is Graphical User Interfaces!

Python has tons of them available. How many different versions of a GUI window 
do we REALLY need. People, a StaticText is a StaticText, a Dialog is a Dialog, 
a ProgressBar is a ProgressBar, an EditText is an EditText, a Canvas is a 
Canvas, a NoteBook is a NoteBook, a ListControl is a ListControl; BLAH! 

If we are going to split into sects, then we should at least abstract away 
the parts that we agree on, and then collectively EXTEND our selfish versions 
from that single abstraction. 

Do you people realize how far we could have evolved a single GUI library by now 
if we were not wasting our time re-inventing the same old widgets again and 
again just because we cannot agree on minutiae! You would rather fragment the 
community and slow evolution than to make compromises and produce something 
greater than the combination of ALL the multiple projects out there? 
Fragmentation is foolish. We need to focus or energies wisely and work towards 
a common goal. This is the path of intelligent evolution, not a billion years 
of naive dice rolling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 3:20 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 If we are going to split into sects, then we should at least abstract away 
 the parts that we agree on, and then collectively EXTEND our selfish versions 
 from that single abstraction.

We've already done that. We've agreed that a program is stored in zero
or more files. Everything after that is an extension from that basic
abstraction.

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


Re: Cloudicy.com - New Social Network

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 3:15 AM, Tufan Cakiroglu
tufancakiro...@hotmail.com wrote:
 Hi. I am owner of www.cloudicy.com

 Cloudicy.com is a new cloud dictionary and website. Its a kind of Social 
 Network. Users can create topics on website and post informations, 
 suggestions, comments and critiques for posts.

 I need users (for manage posts and testing) and PHP developers.

And this is applicable to Python... how?

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


Re: listbox binding..what is the current selection?

2013-03-07 Thread Rick Johnson
On Thursday, March 7, 2013 9:13:16 AM UTC-6, William Ray Wing wrote:
 With apologies for jumping into the middle of this
 discussion, but I've found the most helpful tkinter v8.5
 docs to be the set at New Mexico tech:

Well these are free and open forums the last time i checked. Don't worry, 
nobody is going to get upset because you offered your opinions. I mean, the 
worst think that could happen is if someone offers up the exact same 
information that had already been offered early in the thread because they were 
too lazy to read the thread in full, and now they look like a complete boob ( a 
helpful boob, but a boob none-the-less). But that's just a crazy hypothetical 
situation. You would never do that. So no need to worry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Ian Kelly
On Thu, Mar 7, 2013 at 9:20 AM, Christian Heimes christ...@python.org wrote:
 Am 07.03.2013 17:00, schrieb Ian Kelly:
 On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier
 wolfgang.ma...@biologie.uni-freiburg.de wrote:
 Well, it skips the costly len() call because your iter(Foo()) returns
 iter(range()) under the hood and list() uses that object's __len__() method.

 Iterators do not generally have __len__ methods.

 len(iter(range(10)))
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: object of type 'range_iterator' has no len()

 But iterators have a length hint method that are used for some
 optimizations and preallocations, too.

 i = iter(range(10))
 i.__length_hint__()
 10

 See http://www.python.org/dev/peps/pep-0424/

Didn't know about that, thanks.  Presumably a proper iter(QuerySet())
object could implement __length_hint__ in an efficient manner rather
than by just calling the __len__ of the underlying QuerySet,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Joel Goldstick
On Thu, Mar 7, 2013 at 11:22 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:

 I have fixed this!
 Still ahve allok and you will see that in both of my images they appear in
 the firstpage of superhost.gr

 the output of .py files appear fine except of that ehen a visitor click on
 my first 2 image links he also sees as first line this:

 print ( Content-type: text/html; charset=utf-8\n )

 this is because the above code is a header and its contained to every cgi
 .py file that i generate html ouput from via os.system()

 Can this be somehow eliminated?
 --


That page is not valid html.  View the source in your browser to see -- it
has no html tag, no head, no body.  fix that stuff

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




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread rusi
On Mar 7, 2:52 pm, Sven sven...@gmail.com wrote:

 This thread reminds me of an article I read recently:

 http://rubiken.com/blog/2013/02/11/web-dev-a-crazy-world.html


Ha Ha!  Thanks for that.
Of course its exaggerated.  But then hyperbole can tell a story that
logic cannot.

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


Re: Unhelpful traceback

2013-03-07 Thread John Nagle
On 3/7/2013 5:10 AM, Dave Angel wrote:
 On 03/07/2013 01:33 AM, John Nagle wrote:
 Here's a traceback that's not helping:

 
 A bit more context would be helpful.  Starting with Python version.

Sorry, Python 2.7.

 
 If that isn't enough, then please give the whole context, such as where
 zipelt and filename came from.  And don't forget to specify Python
 version.  Version 3.x treats nonbinary files very differently than 2.x

 Here it is, with some email wrap problems.

John Nagle


def dofilecsv(self, infilename, infdraw) :

Loader for Companies House company data, with files already open.

self.logger.info('Converting %s' % (infilename, ))# log
(pathpart, filepart) = os.path.split(infilename)#
split off file part to construct outputfile)
(outfile, ext) = os.path.splitext(filepart) #
remove extension
outfile += .sql   #
add SQL suffix
outfilename = os.path.abspath(os.path.join(self.options.destdir,
outfile))
#   ***NEED TO INSURE UNIQUE OUTFILENAME EVEN IF DUPLICATED IN
ZIP FILES***
decoder = codecs.getreader('utf-8') #
UTF-8 reader
with decoder(infdraw,errors=replace) as infd :
with codecs.open(outfilename, encoding='utf-8', mode='w') as
outfd :
headerline = infd.readline()#
read header line
self.doheaderline(headerline)   #
process header line
reader = csv.reader(infd, delimiter=',', quotechar='')
# CSV file
for fields in reader :  #
read entire CSV file
self.doline(outfd, fields)  #
copy fields
self.logstats(infilename)   #
log statistics of this file

def dofilezip(self, infilename) :

Do a ZIP file containing CSV files.

try :
inzip = zipfile.ZipFile(infilename, r, allowZip64=True)
# try to open
zipdir = inzip.infolist()   # get
objects in file
for zipelt in zipdir :  # for all
objects in file
self.logger.debug('ZIP file %s contains %s.' %
(infilename, zipelt.filename))
(infile, ext) = os.path.splitext(zipelt.filename) #
remove extension
if ext.lower() == .csv :   # if a CSV file
with inzip.open(zipelt.filename,r) as infd :
  # do this file
self.dofilecsv(infile, infd)# as a CSV file
else :
self.logger.error('Non-CSV file in ZIP file: %s' %
(zipelt.filename,))
self.errorcount += 1# tally

except zipfile.BadZipfile as message :  # if trouble
self.logger.error('Bad ZIP file: %s' % (infilename,))  #
note trouble
self.errorcount += 1# tally

def dofile(self, infilename) :

Loader for Companies House company data

(sink, ext) = os.path.splitext(infilename) # get extension
if ext == .zip :   # if .ZIP file
self.dofilezip(infilename)  # do ZIP file
elif ext == .csv :
self.logger.info('Converting %s' % (infilename,))# log
with open(infilename, rb) as infd :
self.dofilecsv(infilename, infd)# do
self.logstats(infilename)   # log statistics
of this file
else :
self.logger.error('File of unexpected type (not .csv or
.zip): %s ' % (infilename,))
self.errorcount += 1



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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Joel Goldstick
On Thu, Mar 7, 2013 at 12:41 PM, Joel Goldstick joel.goldst...@gmail.comwrote:




 On Thu, Mar 7, 2013 at 11:22 AM, Νίκος Γκρ33κ nikos.gr...@gmail.comwrote:

 I have fixed this!
 Still ahve allok and you will see that in both of my images they appear
 in the firstpage of superhost.gr

 the output of .py files appear fine except of that ehen a visitor click
 on my first 2 image links he also sees as first line this:

 print ( Content-type: text/html; charset=utf-8\n )

 this is because the above code is a header and its contained to every cgi
 .py file that i generate html ouput from via os.system()

 Can this be somehow eliminated?


This may have to do with the configuration of your server.  There may be
differences in how to do that for python 2.x and python 3.x.  I can't help
you more than that


 --


 That page is not valid html.  View the source in your browser to see -- it
 has no html tag, no head, no body.  fix that stuff

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




 --
 Joel Goldstick
 http://joelgoldstick.com




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Joel Goldstick
On Thu, Mar 7, 2013 at 1:51 PM, rh richard_hubb...@lavabit.com wrote:

 On Thu, 7 Mar 2013 07:57:33 -0800 (PST)
 Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 
  I found it! I have placed 'htmltemp' within the os.system() call.
  Otherwise, os.system() returns a return value (int) which python then
  tries to concatenate with htmltemp (string).
 
  os.system( 'python metrites.py  %s' % htmltemp )

 Can also do
 sterrs = 'errorsout'
 os.system( 'python metrites.py  {0} 2 {1}'.format(htmltemp,sterrs))

 It's more 3ish, or 3ist or 3like.
 
  :-)

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


The content type situation is discussed here
http://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Stefan Behnel
Ian Kelly, 07.03.2013 18:31:
 On Thu, Mar 7, 2013 at 9:20 AM, Christian Heimes wrote:
 Am 07.03.2013 17:00, schrieb Ian Kelly:
 On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier wrote:
 Well, it skips the costly len() call because your iter(Foo()) returns
 iter(range()) under the hood and list() uses that object's __len__() 
 method.

 Iterators do not generally have __len__ methods.

  len(iter(range(10)))
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: object of type 'range_iterator' has no len()

 But iterators have a length hint method that are used for some
 optimizations and preallocations, too.

  i = iter(range(10))
  i.__length_hint__()
 10

 See http://www.python.org/dev/peps/pep-0424/
 
 Didn't know about that, thanks.  Presumably a proper iter(QuerySet())
 object could implement __length_hint__ in an efficient manner rather
 than by just calling the __len__ of the underlying QuerySet,

And how exactly would it do that, without either doing what __len__ does or
reading the whole result set into memory?

Stefan


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


April 5 conference on Python in Finance (NYC)

2013-03-07 Thread Shiuan Butler
As Python programmers, you may be interested in participating in an upcoming 
Python in Finance conference, an all-day event taking place in New York on 
the 5th of April (www.python-in-finance.com).

The event brings together 300+ Python practitioners with a who's who line up of 
speakers from the world of Python and finance: Travis Oliphant (Numpy), Wes 
McKinney (Pandas), Andreas Kloeckner (PyCUDA and PyOpenCL), Peter Wang (Chaco) 
... the list goes on. And I am very excited to announce that Claudia Perlich, 
Chief Scientist at m6d, will be giving the keynote address to kick off the 
event; Claudia's list of achievements include being a three-time winner of the 
KDD cup, and numerous and notable contributions in the Machine Learning, Data 
Mining and Predictive Modeling worlds. It's going to be an informative, 
exciting and fun day of great speakers mixed with practitioners of Python in 
Finance.

We have managed to get some great sponsors for the event to keep the attendance 
fee at a rock bottom rate of less than three hundred dollars; not bad for an 
all-day event in New York city with lunch thrown in!

I have a special offer just for you; use the code QUANT at 
www.python-in-finance.com and save 25% off. The event is filling up fast so if 
you plan on coming, register soon; and be sure to let your friends and 
colleagues know about the event. 

Shiuan Butler
www.python-in-finance.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Joel Goldstick
On Thu, Mar 7, 2013 at 1:57 PM, Joel Goldstick joel.goldst...@gmail.comwrote:




 On Thu, Mar 7, 2013 at 1:51 PM, rh richard_hubb...@lavabit.com wrote:

 On Thu, 7 Mar 2013 07:57:33 -0800 (PST)
 Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 
  I found it! I have placed 'htmltemp' within the os.system() call.
  Otherwise, os.system() returns a return value (int) which python then
  tries to concatenate with htmltemp (string).
 
  os.system( 'python metrites.py  %s' % htmltemp )

 Can also do
 sterrs = 'errorsout'
 os.system( 'python metrites.py  {0} 2 {1}'.format(htmltemp,sterrs))

 It's more 3ish, or 3ist or 3like.
 
  :-)

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


 The content type situation is discussed here
 http://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2

 --
 Joel Goldstick
 http://joelgoldstick.com



So, I see you fixed the problem.  How?

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert comma in number?

2013-03-07 Thread John Posner
Peter Otten wrote:

 Last not least there's the option to employ locale-aware formatting:


Not quite last ... there's the mind-bending regular expression route:

   import re
   re.sub(r(?=\d)(?=(\d\d\d)+$), ,, 12345678)   # 12,345,678
   re.sub(r(?=\d)(?=(\d\d\d)+$), ,, -54321) # -54,321

-John



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


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Νίκος Γκρ33κ
Τη Πέμπτη, 7 Μαρτίου 2013 9:36:33 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε:

  So, I see you fixed the problem.  How?

Apart from appearing ugly its not causing any more trouble(other than some 
issues that i have fixed), so i will just d:

os.system( 'python %s  %s' % (htmlpage, temp) )
f = open( temp )
htmldata = f.read()
htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', 
'' )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error when i switched from python v2.6.6 = v3.2.3

2013-03-07 Thread Ian Kelly
On Thu, Mar 7, 2013 at 1:04 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 Τη Πέμπτη, 7 Μαρτίου 2013 9:36:33 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε:

  So, I see you fixed the problem.  How?

 Apart from appearing ugly its not causing any more trouble(other than some 
 issues that i have fixed), so i will just d:

 os.system( 'python %s  %s' % (htmlpage, temp) )
 f = open( temp )
 htmldata = f.read()
 htmldata = htmldata.replace( 'Content-type: text/html; 
 charset=utf-8', '' )

If htmlpage is being pulled from the HTTP request as I think it is,
then you have a code injection vulnerability here.  Think what could
happen if htmlpage were something like this:

-c ''; rm -rf /; oops.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Ian Kelly
On Thu, Mar 7, 2013 at 12:19 PM, Stefan Behnel stefan...@behnel.de wrote:
 Didn't know about that, thanks.  Presumably a proper iter(QuerySet())
 object could implement __length_hint__ in an efficient manner rather
 than by just calling the __len__ of the underlying QuerySet,

 And how exactly would it do that, without either doing what __len__ does or
 reading the whole result set into memory?

If the underlying cursor provides its own efficient length hint, it
could return that.  Or if the query is result-limited, use the limit
as a length hint, provided it's not absurdly large.  And if you really
can't efficiently determine anything about the length of the result
set at all, you can always fall back on returning NotImplemented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Terry Reedy

On 3/7/2013 11:00 AM, Ian Kelly wrote:


But on this point, you are correct.  The mongoengine QuerySet.__iter__
method is defined as:

 def __iter__(self):
 self.rewind()
 return self

This is unfortunate design.  Not only does it mean that the iterator's
__len__ method cannot be trusted (what should the __len__ of a
partially exhausted iterator return?), but it also means that requesting
an iterator over the QuerySet will also silently invalidate any
existing iterators.


I view that design as a violation of the iterator protocol and hence a 
program bug. __iter__ should either *just* return self (if the self is 
an iterator) or return a new object (if self is a non-iterator 
iterable). File objects are iterators and .__iter__ does not rewind.


 f = open(f:/python/mypy/tem.py)
 next(f)
'class myit(list):\n'
 f2 = iter(f)
 f2 is f
True
 next(f2)
def __bytes__(self): return b'hello'\n

--
Terry Jan Reedy

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


Need help deriving a convertion function on python

2013-03-07 Thread johnnyukpo
Good day,

I have a computer programming assignment. I am completely lost and i need some 
help.

These are the questions that are confusing me 
(a) Write a function which converts from gallons to cups2
(b) Now we’d like to be able to convert from cups to milliliters, since metric 
measurements
are easier to convert between. Implement a function which does this.
(c) We’d also like to be able to easily convert gallons into milliliters, so 
implement a
function which does this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Terry Reedy

On 3/7/2013 11:20 AM, Christian Heimes wrote:


But iterators have a length hint method that are used for some
optimizations and preallocations, too.


This is easy when the base iterable has a length method, as do range 
objects.



i = iter(range(10))
i.__length_hint__()

10


And the length_hint can (should be) decremented with each next call.

 next(i); next(i)
0
1
 i.__length_hint__()
8

--
Terry Jan Reedy

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


Re: Need help deriving a convertion function on python

2013-03-07 Thread Chris Angelico
On Fri, Mar 8, 2013 at 7:25 AM,  johnnyu...@gmail.com wrote:
 Good day,

 I have a computer programming assignment. I am completely lost and i need 
 some help.

 These are the questions that are confusing me
 (a) Write a function which converts from gallons to cups2
 (b) Now we’d like to be able to convert from cups to milliliters, since 
 metric measurements
 are easier to convert between. Implement a function which does this.
 (c) We’d also like to be able to easily convert gallons into milliliters, so 
 implement a
 function which does this

Here's a good place to start:

http://docs.python.org/3/tutorial/

After that, think about your task as three sub-tasks:

1) Get and parse input - what does your human need to tell your program?
2) Processing - the actual conversion, the meaty mathematical stuff
3) Produce output - what does your program report to your human?

Then start work on any one of the three. If you get stuck, move on to
one of the others. Once you've put some code together, test it, play
with it, and refine it. And if you get stuck, THEN come and ask for
help; but first, try to solve the problem yourself.

The purpose of this assignment is to help you learn to write code, so
we're not going to simply give you the code :) By the way, you may
find the python-tutor list more suitable, if you feel your questions
are particularly basic:
http://mail.python.org/mailman/listinfo/tutor

The Python tutorial really is a very good place to start. I'm
seriously considering giving it to a ten-year-old girl, granting her
just IDLE and a web browser, and seeing what she can accomplish in a
day.

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


Re: Interesting list() un-optimization

2013-03-07 Thread Wolfgang Maier

  Iterators do not generally have __len__ methods.
 
   len(iter(range(10)))
  Traceback (most recent call last):
File stdin, line 1, in module
  TypeError: object of type 'range_iterator' has no len()
 
  But iterators have a length hint method that are used for some
  optimizations and preallocations, too.
 
   i = iter(range(10))
   i.__length_hint__()
  10
 
  See http://www.python.org/dev/peps/pep-0424/
 

very interesting (hadn't heard of it)! Just checked the PEP,
then tested list()'s behavior, and it is just as described:

class stupid(list):
def __len__(self):
print ('len() called')
return NotImplemented

def __length_hint__(self):
print ('hint requested')
l=iter(self).__length_hint__()
print (l)
return l

a=stupid((1,2,3))
len(d)
==
  len() called

  Traceback (most recent call last):
File pyshell#79, line 1, in module
  len(d)
  TypeError: an integer is required

list(d)
==
  len() called
  hint requested
  3
  [1, 2, 3]

so list() first tries to call the iterable's __len__ method. If that raises a
TypeError it falls back to __length_hint__ .
What I still don't know is how the listiterator object's __length_hint__ works.
Why, in this case, does it know that it has a length of 3 ? The PEP does not
provide any hint how a reasonable hint could be calculated.

 And how exactly would it do that, without either doing what __len__ does or
 reading the whole result set into memory?
 
 Stefan
 

a very good question.

Best,
Wolfgang



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


Python and Hidden Markov Model

2013-03-07 Thread subhabangalore
Dear Group,

I was trying to learn Hidden Markov Model. In Python there are various 
packages, but I was willing to do some basic calculation starting from the 
scratch so that I can learn the model very aptly. Do you know of any thing such?

Thanking you in Advance,
Regards,
Subhabrata. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Russell E. Owen
In article 
3d9fe0b2-7931-4ab6-8929-235460729...@q9g2000pbf.googlegroups.com,
 rusi rustompm...@gmail.com wrote:

 On Mar 6, 11:03 pm, Jason Hsu jhsu802...@gmail.com wrote:
  I'm currently in the process of learning Ruby on Rails.  I'm going through 
  the Rails for Zombies tutorial, and I'm seeing the power of Rails.
 
  I still need to get a Ruby on Rails site up and running for the world to 
  see.  (My first serious RoR site will profile mutual funds from a value 
  investor's point of view.)
 
  I have an existing web site and project called Doppler Value Investing 
  (dopplervalueinvesting.com) that uses Drupal to display the web pages and 
  Python web-scraping scripts to create *.csv and *.html files showing 
  information on individual stocks.  My site has a tacked-on feel to it, and 
  I definitely want to change the setup.
 
  At a future time, I will rebuild my Doppler Value Investing web site in 
  either Ruby on Rails or Django.  The Ruby on Rails route will require 
  rewriting my Python script in Ruby.  The Django route will require learning 
  Django.  (I'm not sure which one will be easier.)
 
  My questions:
  1.  Why is Ruby on Rails much more popular than Django?
 
 Where there is choice there is no freedom
 http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamurti-8th-pu
 blic-talk
 
 Python-for-web offered so much choice -- zope, django, turbogears,
 cherrypy, web.py etc etc -- that the newbie was completely drowned.
 With Ruby there is only one choice to make -- choose Ruby and rails
 follows.
 
 Anyone who's used emacs will know this as the bane of FLOSS software
 -- 100 ways of doing something and none perfect -- IOW too much
 spurious choice.
 
 GvR understood and rigorously implemented a dictum that Nicklaus Wirth
 formulated decades ago -- The most important thing about language
 design is what to leave out. Therefore Python is a beautiful
 language.  Unfortunately the same leadership did not carry over to web
 frameworks and so we have a mess.
 
 I guess the situation is being corrected with google putting its
 artillery behind django.

I strongly agree. The fact that there is no de-facto standard web system 
for Python is a major problem. Consider:
- With too many choice one has no idea which projects will be maintained 
and which will be abandoned.
- Expert knowledge among users is spread more thinly.
- The effort of contributors is diluted.

Years ago when I had some simple web programming to do I looked at the 
choices, gave up and used PHP (which I hated, but got the job done). If 
RoR had been available I would have been much happier using that.

In my opinion the plethora of Python web frameworks is a serious 
detriment to trust and wider acceptance of Python for this use. If  
Django is becoming this standard, that is excellent news.

Some choice is good, but in my opinion too much choice and lack of a 
de-facto standard are very detrimental.

-- Russell

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


Re: Unhelpful traceback

2013-03-07 Thread John Nagle
On 3/7/2013 5:10 AM, Dave Angel wrote:
 On 03/07/2013 01:33 AM, John Nagle wrote:


 infdraw is a stream from the zip module, create like this:

  with inzip.open(zipelt.filename,r) as infd :
 
 You probably need a 'rb' rather than 'r', since the file is not ASCII.
 
  self.dofilecsv(infile, infd)

 This works for data records that are pure ASCII, but as soon as some
 non-ASCII character comes through, it fails.

   No, the ZIP module gives you back the bytes you
put in.  rb is not accepted there:

  File InfoCompaniesHouse.py, line 197, in dofilezip
with inzip.open(zipelt.filename,rb) as infd :# do this
file
  File C:\python27\lib\zipfile.py, line 872, in open
raise RuntimeError, 'open() requires mode r, U, or rU'
RuntimeError: open() requires mode r, U, or rU

   b for files is about end of line handling (CR LF - LF), anyway.

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


Re: Unhelpful traceback

2013-03-07 Thread John Nagle
On 3/7/2013 10:42 AM, John Nagle wrote:
 On 3/7/2013 5:10 AM, Dave Angel wrote:
 On 03/07/2013 01:33 AM, John Nagle wrote:
 Here's a traceback that's not helping:


 A bit more context would be helpful.  Starting with Python version.
 
 Sorry, Python 2.7.

The trouble comes from here:

decoder = codecs.getreader('utf-8')  # UTF-8 reader
with decoder(infdraw,errors=replace) as infd :

It's not the CSV module that's blowing up.  If I just feed the
raw unconverted bytes from the ZIP module into the CSV module,
the CSV module runs without complaint.

I've tried 'utf-8', 'ascii', and 'windows-1252' as codecs.
They all blow up. 'errors=replace' doesn't help.

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


Re: Need help deriving a convertion function on python

2013-03-07 Thread Rick Johnson
On Thursday, March 7, 2013 2:25:42 PM UTC-6, johnn...@gmail.com wrote:
 I have a computer programming assignment. I am completely
 lost and i need some help. These are the questions that
 are confusing me

 (a) Write a function which converts from gallons to cups2

How can we help you if we have no idea of what level of programming experience 
you have attained. Can you write functions? Can you declare variables? What 
about mathematics? If you can already do all these things then make an attempt 
to accomplish problem (a) and then ask us a specific question when you run 
into trouble.

 (b) Now we’d like to be able to convert from cups to
 milliliters, since metric measurements  are easier to
 convert between. Implement a function which does this.

 (c) We’d also like to be able to easily convert gallons
 into milliliters, so implement a function which does this

In due time grasshopper. First make an attempt to solve problem (a). Chris 
gave some great advice however i would like to insert a step 0 into his 
advice list (this is python after all ;-).

 * STEP 0: Learn how to convert from gallons to cups using a
   pencil and paper only.

 * STEP 1: Read docs and learn about functions (if applicable).

 * STEP 2: Try to write a python function that will take one
   parameter (representing the number of gallons) and then
   perform the mathematical equations required to deduce the
   number of cups in a gallon, THEN return the result.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unhelpful traceback

2013-03-07 Thread Ian Kelly
On Thu, Mar 7, 2013 at 3:13 PM, John Nagle na...@animats.com wrote:
 On 3/7/2013 10:42 AM, John Nagle wrote:
 On 3/7/2013 5:10 AM, Dave Angel wrote:
 On 03/07/2013 01:33 AM, John Nagle wrote:
 Here's a traceback that's not helping:


 A bit more context would be helpful.  Starting with Python version.

 Sorry, Python 2.7.

 The trouble comes from here:

 decoder = codecs.getreader('utf-8')  # UTF-8 reader
 with decoder(infdraw,errors=replace) as infd :

 It's not the CSV module that's blowing up.  If I just feed the
 raw unconverted bytes from the ZIP module into the CSV module,
 the CSV module runs without complaint.

 I've tried 'utf-8', 'ascii', and 'windows-1252' as codecs.
 They all blow up. 'errors=replace' doesn't help.

I believe that the csv module is expecting string data, not unicode.
Since it receives unicode as a result of your decoder step, it tries
to convert it to a string using str(), which implicitly tries to
encode the data using the ascii codec, hence the error that you're
seeing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list() un-optimization

2013-03-07 Thread Terry Reedy

On 3/7/2013 3:41 PM, Wolfgang Maier wrote:



Iterators do not generally have __len__ methods.


len(iter(range(10)))

Traceback (most recent call last):
   File stdin, line 1, in module
TypeError: object of type 'range_iterator' has no len()


But iterators have a length hint method that are used for some
optimizations and preallocations, too.


i = iter(range(10))
i.__length_hint__()

10

See http://www.python.org/dev/peps/pep-0424/




very interesting (hadn't heard of it)! Just checked the PEP,
then tested list()'s behavior, and it is just as described:

class stupid(list):
def __len__(self):
print ('len() called')
return NotImplemented

def __length_hint__(self):
print ('hint requested')
l=iter(self).__length_hint__()
print (l)
return l

a=stupid((1,2,3))
len(d)
==
   len() called

   Traceback (most recent call last):
 File pyshell#79, line 1, in module
   len(d)
   TypeError: an integer is required

list(d)
==
   len() called
   hint requested
   3
   [1, 2, 3]

so list() first tries to call the iterable's __len__ method. If that raises a
TypeError it falls back to __length_hint__ .
What I still don't know is how the listiterator object's __length_hint__ works.
Why, in this case, does it know that it has a length of 3 ? The PEP does not
provide any hint how a reasonable hint could be calculated.


'How' depends on the iterator, but when it has an underlying concrete 
iterable of known length, it should be rather trivial as .__next__ will 
explicitly or implicitly use the count remaining in its operation. Part 
of the justification of adding __length_hint__ is that in many cases it 
is so easy. Iterators based on an iterator with a length_hint can just 
pass it along.


The list iterator might work with a C pointer to the next item and a 
countdown count initialized to the list length. The __next__ method 
might be something like this mixed C and Python pseudocode:


  if (countdown--) return *(current--);
  else raise StopIteration

(For non-C coders, postfix -- decrements value *after* retrieving it.)
Then __length_hint__ would just return countdown. Tuples would work the 
same way. Sets and dicts would need current-- elaborated to skip over 
empty hash table slots. Range iterators would add the step to current, 
instead of 1.


--
Terry Jan Reedy

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


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 07.03.2013 10:27, schrieb Sven:
 Now I would like to iterate over P and place one N at each point.
 However if you run out of N I'd like to restart from N[0] and carry on
 until all the points have been populated.
 So far I've got (pseudo code)
 
 i = 0
 for point in points:
 put N[i] at point
 if i  len(N):
 i = 0
 
 is this the most pythonic way to accomplish this?

Sounds like
http://docs.python.org/3/library/itertools.html#itertools.repeat
to me.

 Additionally, what if I wanted to pull a random element from N, but I
 want to ensure all elements from N have been used before starting to
 pick already chosen random elements again.
 So far I thought of duplicating the list and removing the randomly
 chosen elements from the list, and when it's empty, re-copying it. But
 that seems a little wrong if you know what I mean.

This can be done with
http://docs.python.org/3/library/random.html#random.shuffle

untested:

import random

def repeated_random_permutation(iterable):
pool = list(iterable)
while True:
random.shuffle(pool)
yield from pool


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


Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 08.03.2013 00:49, schrieb Alexander Blinne:
 http://docs.python.org/3/library/itertools.html#itertools.repeat

obviously I was aiming for
http://docs.python.org/2/library/itertools.html#itertools.cycle
here

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


Re: Need help deriving a convertion function on python

2013-03-07 Thread Dave Angel

On 03/07/2013 03:40 PM, Chris Angelico wrote:

On Fri, Mar 8, 2013 at 7:25 AM,  johnnyu...@gmail.com wrote:

Good day,

I have a computer programming assignment. I am completely lost and i need some 
help.

These are the questions that are confusing me

SNIP


 By the way, you may
find the python-tutor list more suitable, if you feel your questions
are particularly basic:
http://mail.python.org/mailman/listinfo/tutor



Actually his brother 'akuma upko' (sharing the same account) posted the 
same question on Python-tutor 2 minutes before johnny posted it here.



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


Re: Python and Hidden Markov Model

2013-03-07 Thread Dave Angel

On 03/07/2013 03:48 PM, subhabangal...@gmail.com wrote:

Dear Group,

I was trying to learn Hidden Markov Model. In Python there are various 
packages, but I was willing to do some basic calculation starting from the 
scratch so that I can learn the model very aptly. Do you know of any thing such?



I'm sorry, but I'm having trouble figuring out what you're asking for. 
You said there are packages that could help, but that you want to learn 
more by doing it from scratch.  So what then are you asking for, if not 
packages, sample code or something that's not from scratch ?



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


Re: Unhelpful traceback

2013-03-07 Thread Dave Angel

On 03/07/2013 04:23 PM, John Nagle wrote:



  snip


 raise RuntimeError, 'open() requires mode r, U, or rU'
RuntimeError: open() requires mode r, U, or rU

b for files is about end of line handling (CR LF - LF), anyway.



Only for Python 2.  Since originally you didn't specify, I took my best 
shot. If you omit the 'b' opening a binary file in Python 3, you'd get 
problems similar to yours.  Text files will be converted to Unicode.


That's one of the reasons that specifying the full environment is important.

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


  1   2   3   >