Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 21:20:01 -0700, Ferrous Cranus wrote:

> [Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]   
> File "/home/nikos/public_html/cgi-bin/metrites.py", line 206, in 
> 
> [Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]
> cur.execute('''SELECT hits FROM counters WHERE url = %s''', page )
[...]
> TypeError: unsupported operand type(s) for %: 'bytes' and 'str'

Oh look, it's exactly the same error you started with. Congratulations, 
you've made exactly no progress. As I asked you yesterday:

And what result does form.getvalue return?

What is its type? Is it a list, a tuple, a dict, a bytes object,
a float, a str object, something else?


Have you worked that out yet? If you can't work it out, you can guess, 
and then test your guess:


page = form.getvalue('page')
if isinstance(page, list):
 raise TypeError('guessed it was a list, it is a list')


If your guess is wrong, try another guess. Keep going until you work out 
what type page is.

If you can't write to a data file, you can write to the error log:


page = form.getvalue('page')
raise TypeError('type of page is %r' % type(page))


Keep going until you find out what type of data the variable 'page' is 
holding. Now read the error message again:

unsupported operand type(s) for %: 'bytes' and 'str'


Do you understand what that error means? Here is a hint: start a Python 
interactive session, and try things for yourself:


steve@runes:~$ python3.3
Python 3.3.0rc3 (default, Sep 27 2012, 18:31:58) 
[GCC 4.4.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
py>
py> 'string%s' % 'string'
'stringstring'
py> 
py> b'bytes%s' % b'bytes'
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes'


Do you see a pattern yet? What do you think will happen if you run this?


b'bytes%s' % 'string'


Try it and see for yourself.


Now look at the error message you are getting. Is it the same error 
message? Do you think that perhaps it has the same cause? How do you 
think you might solve this problem?

Hint: if you have a data item that is type A, and you need it to be type 
B, you need to convert from A to B.


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


Re: Lettuce vs Behave

2013-08-28 Thread Ben Finney
cutems93  writes:

> However, it seems these two [Lettuce and Behave] are very similar in
> the way they function. As professionals, what do you prefer and why?

I haven't used both, and have only begun using Behave.

The Behave documentation compares it with Lettuce here
http://pythonhosted.org/behave/comparison.html#lettuce>.

-- 
 \“Odious ideas are not entitled to hide from criticism behind |
  `\  the human shield of their believers' feelings.” —Richard |
_o__) Stallman |
Ben Finney

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Nick the Gr33k

Στις 29/8/2013 7:29 πμ, ο/η Ferrous Cranus έγραψε:

Τη Πέμπτη, 29 Αυγούστου 2013 3:59:49 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:


To be explicit:



   chgrp nobody the-file

   chmod g+w the-file

Hello Cameron,

ni...@superhost.gr [~/www]# touch err.out
ni...@superhost.gr [~/www]# ls -l err.out
-rw-rw-r-- 1 nikos nikos 0 Aug 29 04:26 err.out
ni...@superhost.gr [~/www]# chgrp nobody err.out
chgrp: changing group of `err.out': Operation not permitted

As you can see the system does not let me alter even the groupname of a newly 
created text file.

As, for the 'suexec' that you mentioned in another ;post of yours, old VPS had 
it enabled yes, the new one does not. Should i ask them to enable it back?
Would it help if we enabled it back?
Perhaps 'suexec' would allow Apache(running under user nobody) to switch 
to another more privileged user prior of writing to 
'/home/nikos/www/err.out'


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Πέμπτη, 29 Αυγούστου 2013 3:59:49 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:

> To be explicit:
> 
> 
> 
>   chgrp nobody the-file
> 
>   chmod g+w the-file

Hello Cameron,

ni...@superhost.gr [~/www]# touch err.out
ni...@superhost.gr [~/www]# ls -l err.out
-rw-rw-r-- 1 nikos nikos 0 Aug 29 04:26 err.out
ni...@superhost.gr [~/www]# chgrp nobody err.out 
chgrp: changing group of `err.out': Operation not permitted

As you can see the system does not let me alter even the groupname of a newly 
created text file.

As, for the 'suexec' that you mentioned in another ;post of yours, old VPS had 
it enabled yes, the new one does not. Should i ask them to enable it back?
Would it help if we enabled it back?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Steven D'Aprano
On Thu, 29 Aug 2013 04:48:26 +0430, Mohsen Pahlevanzadeh wrote:

> Dear all,
> 
> I'm C++ programmer and unfortunately put semicolon at end of my
> statements in python.
> 
> Quesion:
> What's really defferences between putting semicolon and don't put?


It's about the same as writing this:


x = 1
pass
y = 2
pass
z = x**2 + y**2
pass
print z
pass



except you save three keystrokes per LOC.


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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Πέμπτη, 29 Αυγούστου 2013 1:56:55 π.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Wed, 28 Aug 2013 06:11:13 -0700, Ferrous Cranus wrote:
> 
> 
> 
> > This si what iam tryign now since the function ishish proposed wont help
> 
> > me.
> 
> 
> 
> I see that your apology for careless writing didn't last very long.
> 
> 
> 
> [...]
> 
> > except:
> 
> >   print( repr(e) )
> 
> 
> 
> What is the value of "e" here, and where is it defined?
> 
> 
> 
> Let's look at the error in your log file:
> 
> 
> 
> 
> 
> > [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print(
> 
> > repr(e) ) [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
> 
> > NameError: name 'e' is not defined
> 
> 
> 
> 
> 
> Did you bother to read the error before asking for help?
> 
> 
> 
> Variable 'e' is not defined. Perhaps you should define it?

Yes indeed , that was a a syntax error by me:

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()#URL is unique, so should only be one
except Exception as e:
con.rollback()#something failed, rollback the entire transaction
print( repr(e) )

outputs:
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 206, in 
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] 
cur.execute('''SELECT hits FROM counters WHERE url = %s''', page )
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]   File 
"/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 
108, in execute
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] query = query % 
escaped_args

[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 206, in 
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] 
cur.execute('''SELECT hits FROM counters WHERE url = %s''', page )
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154]   File 
"/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 
108, in execute
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] query = query % 
escaped_args
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] TypeError: 
unsupported operand type(s) for %: 'bytes' and 'str'


Now at least 'superhost.gr' displays the error when one by browser 
http://superhost.gr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
On Thu, 29 Aug 2013 11:39:25 +1000, Chris Angelico wrote:

> The novice thinks his primary job is to stop the program from crashing.
> The expert knows that a crash is just another way for things to go
> wrong, and one of the easiest to deal with.

"I find it amusing when novice programmers believe their main job is 
preventing programs from crashing. ... More experienced programmers 
realize that correct code is great, code that crashes could use 
improvement, but incorrect code that doesn’t crash is a horrible 
nightmare."

http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/

Anyone who hasn't already done so, you should read the whole article. 
It's about static versus dynamic typing, testing, proving correctness, 
and how they all fit in together.


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


Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 11:20 AM, Cameron Simpson  wrote:
> However, when working in Java its type strictness caught a great
> many simple brainfart logic errors by checking function signatures;
> typically calling the wrong function/method or mangling arguments.
> Getting this stuff up front was handy.

It certainly is useful, which is why I like a language with declared
types. But it's not everything, and it's certainly far from
sufficient. So once you've decided that run-time errors are normal,
you write code with that in mind (in a web server, for instance, you'd
have some code around the outside that catches and logs errors and
returns a 500 to the client), and then you don't stress about them.
Any you can catch early, do so, but don't put more effort into
catching errors early than you save by not having them later.

The novice thinks his primary job is to stop the program from
crashing. The expert knows that a crash is just another way for things
to go wrong, and one of the easiest to deal with.

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


Re: Interface and duck typing woes

2013-08-28 Thread Roy Smith
In article ,
 Cameron Simpson  wrote:

> Anyway, I digress. My point is that there are plusses to having
> signature/type checking at coding time. It is not the Python Way,
> but I surely cannot be alone in sometimes being frustrated chasing
> a deeply nested runtime error that static type checking might have
> found up front.

One time when I really do miss static typing (and often emulate by 
sprinkling isinstance() assertions into my functions) is when I do a big 
refactoring.

I'll change (to pick a real example) Song.get(id) from taking an integer 
to taking an ObjectId.  I'll hunt through my source code to find all the 
places where I call Song.get(), but usually I'll miss a few.  The 
assertions will help me catch that quickly because I'll get an easy to 
understand exception thrown right at the first point of contact, rather 
than something cryptic happening 12 stack frames down, deep in the 
database layer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Cameron Simpson
On 28Aug2013 12:11, Steven D'Aprano  
wrote:
| On Wed, 28 Aug 2013 01:46:01 -0700, Ferrous Cranus wrote:
| > Also many times when i try to view the error_log by
| > tail -F /usr/local/apache/logs/error_log &
| > 
| > i get realtime scrolling of other joomla webistes pho errors and i have
| > hard time trackign my own webistes erros.
| > 
| > is ther a work around for that?
| 
| That's an apache logging issue, not Python, and I don't know enough about 
| apache to do more than guess that there probably is a solution but I have 
| no idea what it is.

Normal practice is to specify vhost specific log paths inside each
website's VirtualHost clause, thus splitting the log for each
website out into separate files.

http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost

Notice the ErrorLog directive inside the clause.

Cheers,
-- 
Cameron Simpson 

"What the hell are we supposed to use, man -- harsh language?"
"Flame units only." - _Aliens_
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Cameron Simpson
On 28Aug2013 18:44, Prasad, Ramit  
wrote:
| Ferrous Cranus wrote:
| > Yes Uli, the script metrits.py is being invoked by Apache Web Server which 
in turn runs under user
| > Nobody.
| > So, that mean that? user 'nobody' has no write permission to /home/nikos 
folder?

As Ramit says, yes. Your own directory listing earlier showed "r-x" for the
group "nobody"; that says "no write". The file was the same: "r--".

| Yes. You should make it group writable with "nobody" as the group. Use chmod 
and chown
| to change permissions and owners (i.e. groups).

To be explicit:

  chgrp nobody the-file
  chmod g+w the-file

| Normally I would have thought you would have a public_html or www directory 
in your
| home folder that would be readable/writable to the web server (and where you 
should 
| write).

Readable, yes. Writable? Generally mad. Apaches are often configured
to run as "nobody" or "nofiles" specificly to ensure that it cannot
write to stuff. The last thing you want is to have the website's
files writable by the apache; it is asking for defacements and other
hacks.

Nikos should make a specific directory for these files and give
ONLY THAT write permission for "nobody". And then use a full pathname
to the directory in his CGI script - a relative path makes ill
founded assumptions about the current working directory of the
script.

Cheers,
-- 
Cameron Simpson 

A gentleman does not go motoring about after dark.  - J. Lucas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Cameron Simpson
On 28Aug2013 05:48, Nikos  wrote:
| Hi steven , sorry for the typos.
| you are write my script is invoked by apache web server application which it 
runs under account 'nobody'
[...]
| nobody8449  0.0  0.2  65712  3228 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
[...]
| My script were all workign in the previous VPS enviroment, the script is 
correct is just a few minor thing in the new VPS env that they need to be taken 
care of thus prohibit my script to run..

Your previous VPS used "suexec" in the Apache. This one does not.

Cheers,
-- 
Cameron Simpson 

Think positively, act positively, and never leave fingerprints.
- Robert Sneddon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interface and duck typing woes

2013-08-28 Thread Cameron Simpson
On 29Aug2013 09:17, Chris Angelico  wrote:
| On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy  wrote:
| > Depending on who the users will be, I might just not worry about it until an
| > exception is raised. If you try to protect against everything that you might
| > do wrong, you are on the road to madness, as the protection code might also
| > be buggy. (Too much testing has the same problem ;-).
| 
| I'd go further.
| 
| Do you believe that you can write code to catch every bug you might
| make? If so, you are naive and probably haven't spent much time
| programming yet :) And if not, then you must acknowledge that bugs
| WILL happen; therefore you will need to cope with them after the
| event. So rather than trying to prevent them all, just improve your
| means of coping, and you'll accomplish the same end with much less
| trouble.

I'm not so extreme. Yes, of course certain things will only show
at runtime and you should be prepared to have to deal with that.

However, when working in Java its type strictness caught a great
many simple brainfart logic errors by checking function signatures;
typically calling the wrong function/method or mangling arguments.
Getting this stuff up front was handy. Of course there's a price
there in terms of flexibility and all that wordy stuff defining the
functions in the first place. As an aside, you can also get a lot
of this checking in C with aggressive linting and making a bunch
of macros like:

  #define CNULL ((char *)NULL)
  #define CPNULL ((char **)NULL)

and so forth as needed - lint can then catch a lot of otherwise
unchecked comparisons.

Anyway, I digress. My point is that there are plusses to having
signature/type checking at coding time. It is not the Python Way,
but I surely cannot be alone in sometimes being frustrated chasing
a deeply nested runtime error that static type checking might have
found up front.

Cheers,
-- 
Cameron Simpson 

"waste cycles drawing trendy 3D junk"   - Mac Eudora v3 config option
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> This is about Perl, but may be of interest.
> 
> http://www.perl.com/pub/2007/12/06/soto-11.html

I got about halfway through, then raised an uncaught TLDNR Exception.  
But I did like what he had to say about Tcl.

Tcl is under-appreciated.  A few gigs back, I did a lot of work in Tcl.  
We were writing a network management tool (long since subsumed into IBM 
Tivoli via multiple corporate mergers and put out to pasture: 
http://tinyurl.com/qxd4kw9).

The dev team consisted mostly of people who were networking subject 
matter experts and not real programmers.  Tcl turned out to be an 
excellent tool to let the SME's express their networking knowledge in 
executable form without having to learn C++, Java, or even Python.

Tcl is also ridiculously easy to embed.  It's literally one line of C 
code and you've got an embedded Tcl interpreter running.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 10:33 AM, Roy Smith  wrote:
> In article ,
>  Mohsen Pahlevanzadeh  wrote:
>
>> Dear all,
>>
>> I'm C++ programmer and unfortunately put semicolon at end of my
>> statements in python.
>>
>> Quesion:
>> What's really defferences between putting semicolon and don't put?
>
> In theory, nothing.  In practice, all the real Python programmers will
> make fun of you.
>
> Somewhat more seriously, every language has its own way of doing things.
> There's the set of things the language allows you to do, and the
> somewhat smaller set of things that have become accepted as the "proper"
> way to do things in that language.  For Python, putting semicolons at
> the ends of statements falls into the first set but not the second.

This is about Perl, but may be of interest.

http://www.perl.com/pub/2007/12/06/soto-11.html

One of his main points is that languages differ primarily in what they
force you to say - not what you're able to express. C forces you to
declare the ends of statements with semicolons. Python forces you to
be consistent with indentation. Smalltalk (if I have this correct)
forces you to put parentheses in expressions like a+b*c to declare
order of operations. German forces you to match das/die/der to the
noun it's referring to. Doing what a completely different programming
language forces you to do is like speaking with the wrong grammar
("Murdered in the bed we will be! One day we will in bed find
ourselves stone dead!"[1]); native speakers will understand you, but
it doesn't sound fluent.

ChrisA

[1] Mit der knife in der chess! Sun on the Stubble. Great book.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 10:37 AM, Tim Chase
 wrote:
> On 2013-08-29 10:31, Chris Angelico wrote:
>> but putting semicolons at the ends of Python statements is as
>> useless as putting lots of (((irritating (((superfluous
>> (((parentheses) in your C++ code. The parser won't mind,
>> but subsequent programmers will wonder what these unnecessary
>> syntactic elements are for.
>
> That would would be a lisp programmer writing C++ code? :-)

Isn't that what LISP stands for? Lots of Irritating Superfluous Parentheses? :)

I shouldn't talk, though. Never used LISP for anything serious -
nearest I've done is to use Scheme to tinker with GNU Lilypond.

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


Re: semicolon at end of python's statements

2013-08-28 Thread Ned Batchelder

On 8/28/13 8:18 PM, Mohsen Pahlevanzadeh wrote:

Dear all,

I'm C++ programmer and unfortunately put semicolon at end of my
statements in python.

Quesion:
What's really defferences between putting semicolon and don't put?
There is no difference.  The semicolon is unnecessary in Python.  If you 
include them, people will know that you are still thinking in another 
language.


Full disclosure: you can separate statements on a line with semicolons, 
but this practice is strongly discouraged.


--Ned.

Yours,
Mohsen



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


Re: semicolon at end of python's statements

2013-08-28 Thread Roy Smith
In article ,
 Mohsen Pahlevanzadeh  wrote:

> Dear all,
> 
> I'm C++ programmer and unfortunately put semicolon at end of my
> statements in python.
> 
> Quesion:
> What's really defferences between putting semicolon and don't put?

In theory, nothing.  In practice, all the real Python programmers will 
make fun of you.

Somewhat more seriously, every language has its own way of doing things.  
There's the set of things the language allows you to do, and the 
somewhat smaller set of things that have become accepted as the "proper" 
way to do things in that language.  For Python, putting semicolons at 
the ends of statements falls into the first set but not the second.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Tim Chase
On 2013-08-29 10:31, Chris Angelico wrote:
> but putting semicolons at the ends of Python statements is as
> useless as putting lots of (((irritating (((superfluous
> (((parentheses) in your C++ code. The parser won't mind,
> but subsequent programmers will wonder what these unnecessary
> syntactic elements are for.

That would would be a lisp programmer writing C++ code? :-)

-tkc



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


Re: semicolon at end of python's statements

2013-08-28 Thread Tim Chase
On 2013-08-29 04:48, Mohsen Pahlevanzadeh wrote:
> I'm C++ programmer and unfortunately put semicolon at end of my
> statements in python.
> 
> Quesion:
> What's really defferences between putting semicolon and don't put?

>From a technical standpoint, nothing (see below).  From a "readability
on the part of other programmers" standpoint, it's bad practice.  So
if you're coding for yourself, do whichever makes you happy.  If you
want to interact with other Python developers and don't want to make
them grumpy, remove them.

-tkc



>>> def with_semis():
... print 1;
... print 2;
... print 3;
... 
>>> def without_semis():
... print 1
... print 2
... print 3
... 
>>> import dis
>>> dis.dis(with_semis)
  2   0 LOAD_CONST   1 (1)
  3 PRINT_ITEM  
  4 PRINT_NEWLINE   

  3   5 LOAD_CONST   2 (2)
  8 PRINT_ITEM  
  9 PRINT_NEWLINE   

  4  10 LOAD_CONST   3 (3)
 13 PRINT_ITEM  
 14 PRINT_NEWLINE   
 15 LOAD_CONST   0 (None)
 18 RETURN_VALUE
>>> dis.dis(without_semis)
  2   0 LOAD_CONST   1 (1)
  3 PRINT_ITEM  
  4 PRINT_NEWLINE   

  3   5 LOAD_CONST   2 (2)
  8 PRINT_ITEM  
  9 PRINT_NEWLINE   

  4  10 LOAD_CONST   3 (3)
 13 PRINT_ITEM  
 14 PRINT_NEWLINE   
 15 LOAD_CONST   0 (None)
 18 RETURN_VALUE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolon at end of python's statements

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 10:18 AM, Mohsen Pahlevanzadeh
 wrote:
> Dear all,
>
> I'm C++ programmer and unfortunately put semicolon at end of my
> statements in python.
>
> Quesion:
> What's really defferences between putting semicolon and don't put?

Very little. Putting the semicolon makes you look like a C programmer
who's new to Python; omitting it makes you look like you actually
understand Python :)

As a C and C++ programmer myself, I know where you're coming from, but
putting semicolons at the ends of Python statements is as useless as
putting lots of (((irritating (((superfluous
(((parentheses) in your C++ code. The parser won't mind,
but subsequent programmers will wonder what these unnecessary
syntactic elements are for.

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


semicolon at end of python's statements

2013-08-28 Thread Mohsen Pahlevanzadeh
Dear all,

I'm C++ programmer and unfortunately put semicolon at end of my
statements in python.

Quesion:
What's really defferences between putting semicolon and don't put?

Yours,
Mohsen

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 18:56:56 -0400, Joel Goldstick wrote:

> At any rate, isn't
> this stuff really something that the Web Server company should be
> helping him with?  Its their server, they know how it is configured, and
> they can quickly look in his directories to figure out permissions
> related issues.

Perhaps. But Nikos is reporting that his log file shows entries from all 
the other websites on the server, which doesn't sound good to me. Surely 
any decent, competent web server company would be able to ensure that 
each customer sees only their own log entries?



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


Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 18:09:22 -0300, Joe Junior wrote:

> While designing a simple library, I found myself asking a philosophical
> question: to check or not to check the parameter's interface?

The only correct answer to that is, "Yes no maybe".

:-)


> I think that, considering it is Python, the usual answer would be "no",
> but here is the situation that got me thinking:
> 
> class Flock:
> 
> def __init__(self):
> self.ducks= []
> 
> def do_stuff(self):
> for duck in self.ducks:
> duck.quack()
> 
> class Duck:
> 
> def quack(self):
> #quack-quack
> pass
> 
> f = Flock()
> d = Duck()
> f.ducks.append(d)
> f.do_stuff()
> 
> Ok, no big deal there, the problem is if the user forgets to implement
> the quack() method. The stack trace would complain that "duck.quack()"
> is wrong, but that can happen hundreds of lines after the user actually
> added the object to the Flock, and it can be hard to find out what is
> happening and which object is wrong.

True, but that's a good case for improving the error message, or using a 
debugger. Here is Flock.do_stuff re-written to give a more verbose/useful 
error message:


def do_stuff(self):
for i, duck in enumerate(self.ducks):
 try:
 duck.quack()
 except AttributeError:
 raise DuckError(
 'object %r at index %d has no quack' % (duck, i)
 )


Okay, seeing the index is useful. But we would have got nearly as much 
information from the AttributeError traceback, minus the index:

py> (42).quack()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'int' object has no attribute 'quack'

So how much extra work are you prepared to put in to make a rare 
occurrence (passing a magpie instead of a duck) easier to debug? Since 
errors are presumably rare, maybe the answer is "not a lot of extra 
work". But if the consequence of an error is catastrophic ("for want of a 
duck quacking, the nuclear reactor explodes, making the northern 
hemisphere uninhabitable"), maybe the answer is "as much as it takes".

Other questions: what happens if duck.quack is buggy and raises 
AttributeError? A good question, but just how far should we go in 
worrying about things like this? What happens if duck.quack is buggy and 
raises StopIteration? Sometimes the right reaction is to deal with it if 
and when it actually occurs. In other words, wait for the bug report 
before trying to fix it.

("Fix it" may mean telling people "don't do that!".)


> Of course I don't want to check isistance(), I like duck typing, but
> should I check if hasattr() and callable() before adding to the
> container? What is the pythonic way to deal with it? Am I worrying too
> much ;-)?

Yes :-)

Except in the (rare?) case that you aren't worrying enough, in which case 
you can check hasattr and callable up front, or do whatever other tests 
you feel the need to check. It depends on the specific code you are 
writing.



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


Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy  wrote:
> Depending on who the users will be, I might just not worry about it until an
> exception is raised. If you try to protect against everything that you might
> do wrong, you are on the road to madness, as the protection code might also
> be buggy. (Too much testing has the same problem ;-).

I'd go further.

Do you believe that you can write code to catch every bug you might
make? If so, you are naive and probably haven't spent much time
programming yet :) And if not, then you must acknowledge that bugs
WILL happen; therefore you will need to cope with them after the
event. So rather than trying to prevent them all, just improve your
means of coping, and you'll accomplish the same end with much less
trouble.

At this point I could go off into a lengthy discussion of philosophy
and original sin (not "original SYN", which is a different thing
altogether), but anyone who's ever written bug-handling code will
understand what I mean already :)

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 06:11:13 -0700, Ferrous Cranus wrote:

> This si what iam tryign now since the function ishish proposed wont help
> me.

I see that your apology for careless writing didn't last very long.

[...]
> except:
>   print( repr(e) )

What is the value of "e" here, and where is it defined?

Let's look at the error in your log file:


> [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print(
> repr(e) ) [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
> NameError: name 'e' is not defined


Did you bother to read the error before asking for help?

Variable 'e' is not defined. Perhaps you should define it?


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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Joel Goldstick
On Wed, Aug 28, 2013 at 6:49 PM, Steven D'Aprano
 wrote:
> On Wed, 28 Aug 2013 18:44:28 +, Prasad, Ramit wrote:
>
>> Normally I would have thought you would have a public_html or www
>> directory in your home folder that would be readable/writable to the web
>> server (and where you should write).
>
> I expect that he does. But Nikos has tried writing to the Nikos home
> directory, and to .. (the parent directory). I don't believe he has tried
> writing to . (the current directory), or to /tmp. I'm not an expert, but
> I expect that Apache should be able to write to one of those. And if not,
> he has root on his system, he can simply create a writable directory and
> write to that.
>
> I expect that there are security implications of having a directories
> writable to the webserver user, but temporarily creating one for a quick
> debugging aid should be okay.
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list

This thread follows well travelled grounds from several of the
previous Nikos appearances here.  He seems to have problems grasping
permissions as they relate to apache.  He seems to demand cook book
answers as compared to understanding the issues.  At any rate, isn't
this stuff really something that the Web Server company should be
helping him with?  Its their server, they know how it is configured,
and they can quickly look in his directories to figure out permissions
related issues.

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 4:44 AM, Prasad, Ramit
 wrote:
> Normally I would have thought you would have a public_html or www directory 
> in your
> home folder that would be readable/writable to the web server (and where you 
> should
> write).

No, a normal setup would have that world-readable but not writable.
That way, even if an exploit is found in your web site that lets an
attacker write files, s/he can't upload more files to the web server's
directory and start running them.

A directory writable by the web server might be /tmp.

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 18:44:28 +, Prasad, Ramit wrote:

> Normally I would have thought you would have a public_html or www
> directory in your home folder that would be readable/writable to the web
> server (and where you should write).

I expect that he does. But Nikos has tried writing to the Nikos home 
directory, and to .. (the parent directory). I don't believe he has tried 
writing to . (the current directory), or to /tmp. I'm not an expert, but 
I expect that Apache should be able to write to one of those. And if not, 
he has root on his system, he can simply create a writable directory and 
write to that.

I expect that there are security implications of having a directories 
writable to the webserver user, but temporarily creating one for a quick 
debugging aid should be okay.


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


Re: Interface and duck typing woes

2013-08-28 Thread Terry Reedy

On 8/28/2013 5:09 PM, Joe Junior wrote:

While designing a simple library, I found myself asking a
philosophical question: to check or not to check the parameter's
interface?

I think that, considering it is Python, the usual answer would be
"no", but here is the situation that got me thinking:

class Flock:

 def __init__(self):
 self.ducks= []

 def do_stuff(self):
 for duck in self.ducks:
 duck.quack()

class Duck:

 def quack(self):
 #quack-quack
 pass

f = Flock()
d = Duck()
f.ducks.append(d)
f.do_stuff()

Ok, no big deal there, the problem is if the user forgets to implement
the quack() method. The stack trace would complain that "duck.quack()"
is wrong, but that can happen hundreds of lines after the user
actually added the object to the Flock, and it can be hard to find out
what is happening and which object is wrong.

Of course I don't want to check isistance(), I like duck typing, but
should I check if hasattr() and callable() before adding to the
container? What is the pythonic way to deal with it? Am I worrying too
much ;-)?


You could underscore '_ducks' and add a .add_duck method with the checks 
you suggest. Or wrap 'duck.quack()' in try-except and log or warn (or 
even raise) on AttributeError or TypeError (not callable) with an 
informative message. Grepping for 'ducks.append(' will find all 
locations where a non-duck might have been added.


Depending on who the users will be, I might just not worry about it 
until an exception is raised. If you try to protect against everything 
that you might do wrong, you are on the road to madness, as the 
protection code might also be buggy. (Too much testing has the same 
problem ;-).


--
Terry Jan Reedy

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


Re: String splitting with exceptions

2013-08-28 Thread John Levine
>Can you have brackets within brackets? If so, this is impossible to deal
>with within a regex.

Nope.  It's a regular language, not a CFL.

>Otherwise:
 re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
>['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']

That seems to do it, thanks.

-- 
Regards,
John Levine, jo...@iecc.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. http://jl.ly
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving to Python for web

2013-08-28 Thread Andreas Ecaz
On Wednesday, August 28, 2013 11:25:44 PM UTC+2, Andreas Ecaz wrote:
> I've looked at Flask, Bottle and Web.py. I quite like the look of Bottle. 
> I'll keep looking for some other microframeworks, maybe I can find something 
> else that interests me.
> 
> 
> 
> Thank you.

At the moment I'm worried about writing more framework than python (if that 
makes sense) which seems unlikely with MOST microframeworks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving to Python for web

2013-08-28 Thread Andreas Ecaz
On Wednesday, August 28, 2013 11:08:52 PM UTC+2, Joel Goldstick wrote:
> On Wed, Aug 28, 2013 at 4:14 PM,   wrote:
> 
> > So, I have been working in PHP for several years but I want to learn 
> > something new. That something new is Python. But since I'm a web developer 
> > I want to build stuff for the web.
> 
> >
> 
> > I don't want to use Django because it's too bloated, it seem to do 
> > everything for you. I don't like that. I want to do the "plumbing". But at 
> > the same time I have no idea how I would write something that could handle 
> > cookies, sessions, post, get etc etc; so I assume I have to use some kind 
> > of web framework.
> 
> >
> 
> > So, can you recommend a minimal web framework that still allows me to write 
> > in Python? Furthermore, do I even need one? I am currently running NGINX 
> > and I have UWSGI installed. I'm just worried about how I would handle form 
> > submissions, get requests and sessions/cookies.
> 
> >
> 
> > Any advice would be greatly appreciated.
> 
> 
> 
> I like django, but you may want to google "python micro web framework"
> 
> 
> 
> There are a handful with some following so that there are communities,
> 
> docs, etc available
> 
> 
> 
> As to get/cookies/sessions check out the requests module (3rd party -
> 
> well received) http://docs.python-requests.org/en/latest/
> 
> > --
> 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Joel Goldstick
> 
> http://joelgoldstick.com

I've looked at Flask, Bottle and Web.py. I quite like the look of Bottle. I'll 
keep looking for some other microframeworks, maybe I can find something else 
that interests me.

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


Interface and duck typing woes

2013-08-28 Thread Joe Junior
While designing a simple library, I found myself asking a
philosophical question: to check or not to check the parameter's
interface?

I think that, considering it is Python, the usual answer would be
"no", but here is the situation that got me thinking:

class Flock:

def __init__(self):
self.ducks= []

def do_stuff(self):
for duck in self.ducks:
duck.quack()

class Duck:

def quack(self):
#quack-quack
pass

f = Flock()
d = Duck()
f.ducks.append(d)
f.do_stuff()

Ok, no big deal there, the problem is if the user forgets to implement
the quack() method. The stack trace would complain that "duck.quack()"
is wrong, but that can happen hundreds of lines after the user
actually added the object to the Flock, and it can be hard to find out
what is happening and which object is wrong.

Of course I don't want to check isistance(), I like duck typing, but
should I check if hasattr() and callable() before adding to the
container? What is the pythonic way to deal with it? Am I worrying too
much ;-)?

Thanks,

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


Re: Moving to Python for web

2013-08-28 Thread Joel Goldstick
On Wed, Aug 28, 2013 at 4:14 PM,   wrote:
> So, I have been working in PHP for several years but I want to learn 
> something new. That something new is Python. But since I'm a web developer I 
> want to build stuff for the web.
>
> I don't want to use Django because it's too bloated, it seem to do everything 
> for you. I don't like that. I want to do the "plumbing". But at the same time 
> I have no idea how I would write something that could handle cookies, 
> sessions, post, get etc etc; so I assume I have to use some kind of web 
> framework.
>
> So, can you recommend a minimal web framework that still allows me to write 
> in Python? Furthermore, do I even need one? I am currently running NGINX and 
> I have UWSGI installed. I'm just worried about how I would handle form 
> submissions, get requests and sessions/cookies.
>
> Any advice would be greatly appreciated.

I like django, but you may want to google "python micro web framework"

There are a handful with some following so that there are communities,
docs, etc available

As to get/cookies/sessions check out the requests module (3rd party -
well received) http://docs.python-requests.org/en/latest/
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: My attempts in playing with tail-recursion in python

2013-08-28 Thread Thomas Baruchel
Le 28-08-2013, Thomas Baruchel  a écrit :
> The following functions are fully usable; I hope someone will enjoy using
> them.
>
> If you are not interested by the explanations, just jump to the end of the
> message and take my functions for using them.

Despite the very short size of my function, I made a module of it as a
convenience for my own use. I share here my "recursion.py" file in which
I also added some docstrings.

- module "recursion.py" ---

"""
The recursion module provides convenient functions for handling
recursion with lambda functions.

The famous Y-combinator is provided as a convenience, but the most
distinctive function of the module is the B function for handling
tail-recursion.

Written by Thomas Baruchel
"""

Y = lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))

def B(func):
"""
B(lambda) -> lambda

Return a usable function from a lambda expression written with a
tail-recursion style. The new function will be evaluated inside
a loop with no recursive calls, allowing high depths of recursion.

Since the internal loop evaluates the return of the function as long
as it is callable, the function does not work with functions returning
functions (at the end of the recursive calls); there is no restriction
otherwise.

E.g.:
  fac = lambda f: lambda a,b: b if a==0 else f(a-1,a*b)
  func = B(fac)
  func(5,1)
--> 120
or more shortly:
  B(lambda f: lambda a,b: b if a==0 else f(a-1,a*b))(5,1)
--> 120
"""
x = (lambda f: (lambda x: x(x))(lambda y:
  f(lambda *args: lambda: y(y)(*args(func)
def wrapper(*args):
out = x(*args)
while callable(out):
out = out()
return out
return wrapper
-- 
http://mail.python.org/mailman/listinfo/python-list


Moving to Python for web

2013-08-28 Thread ecazs . net
So, I have been working in PHP for several years but I want to learn something 
new. That something new is Python. But since I'm a web developer I want to 
build stuff for the web.

I don't want to use Django because it's too bloated, it seem to do everything 
for you. I don't like that. I want to do the "plumbing". But at the same time I 
have no idea how I would write something that could handle cookies, sessions, 
post, get etc etc; so I assume I have to use some kind of web framework.

So, can you recommend a minimal web framework that still allows me to write in 
Python? Furthermore, do I even need one? I am currently running NGINX and I 
have UWSGI installed. I'm just worried about how I would handle form 
submissions, get requests and sessions/cookies.

Any advice would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3 integer division debugging

2013-08-28 Thread Terry Reedy

On 8/28/2013 11:15 AM, Neal Becker wrote:

The change in integer division seems to be the most insidious source of silent
errors in porting code from python2 - since it changes the behaviour or valid
code silently.


In Python since 2.??, put 'from __future__ import integer_division' 
(sp?) at the top of your code



--
Terry Jan Reedy

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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Josh English
Reduce tricks are nice, but I prefer clarity sometimes:

def double(x):
return x*2

def add3(x):
return x+3


def compose(*funcs):
for func in funcs:
if not callable(func):
raise ValueError('Must pass callable functions')

def inner(value):
for func in funcs:
value = func(value)
return value

return inner


add_then_double = compose(add3, double)
double_then_add = compose(double, add3)

print add_then_double(1) # prints 8
print double_then_add(1) # prints 5
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Prasad, Ramit
Ferrous Cranus wrote:
> Yes Uli, the script metrits.py is being invoked by Apache Web Server which in 
> turn runs under user
> Nobody.
> So, that mean that? user 'nobody' has no write permission to /home/nikos 
> folder?

Yes. You should make it group writable with "nobody" as the group. Use chmod 
and chown
to change permissions and owners (i.e. groups). As a last resort (for testing 
purposes
only!) you can set the directory "world writable", but then *anyone* with 
access to that
host can write/delete/destroy the contents of that directory. This is obviously
very insecure and not a good idea. But if you are only trying to get a quick 
error message
then it might work for you. 

Normally I would have thought you would have a public_html or www directory in 
your
home folder that would be readable/writable to the web server (and where you 
should 
write).


~Ramit



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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Dave Angel
On 28/8/2013 07:38, Ferrous Cranus wrote:


>
> no this is the general error log apache produces for all the server.
>
> Is there a way to grep error logging info, pertainign only to my specific 
> nikos account or my superhost.gr domain?

I now nothing about Apache logs, but how about grepping the client url ?

[client 108.162.231.120]

I still don't understand why you don't find or create a directory that
"nobody" has write access to, so you can be more flexible about what
information you log.

Or strip the problem down to a simple "page" that displays what print
emits in a simple form.

-- 
DaveA

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


Re: String splitting with exceptions

2013-08-28 Thread Peter Otten
Neil Cerutti wrote:

> On 2013-08-28, John Levine  wrote:
>> I have a crufty old DNS provisioning system that I'm rewriting and I
>> hope improving in python.  (It's based on tinydns if you know what
>> that is.)
>>
>> The record formats are, in the worst case, like this:
>>
>> foo.[DOM]::[IP6::4361:6368:6574]:600::
>>
>> What I would like to do is to split this string into a list like this:
>>
>> [ 'foo.[DOM]','','[IP6::4361:6368:6574]','600','' ]
>>
>> Colons are separators except when they're inside square
>> brackets.  I have been messing around with re.split() and
>> re.findall() and haven't been able to come up with either a
>> working separator pattern for split() or a working field
>> pattern for findall().  I came pretty close with findall() but
>> can't get it to reliably match the nothing between two adjacent
>> colons not inside brackets.
>>
>> Any suggestions? I realize I could do it in a loop where I pick
>> stuff off the front of the string, but yuck.
> 
> A little parser, as Skip suggested, is a good way to go.
> 
> The brackets make your string context-sensitive, a difficult
> concept to cleanly parse with a regex.
> 
> I initially hoped a csv module dialect could work, but the quote
> character is (currently) hard-coded to be a single, simple
> character, i.e., I can't tell it to treat [xxx] as "xxx".
> 
> What about Skip's suggestion? A little parser. It might seem
> crass or something, but it really is easier than musceling a
> regex into a context sensitive grammer.
> 
> def dns_split(s):
> in_brackets = False
> b = 0 # index of beginning of current string
> for i, c in enumerate(s):
> if not in_brackets:
> if c == "[":
> in_brackets = True
> elif c == ':':
> yield s[b:i]
> b = i+1
> elif c == "]":
> in_brackets = False

I think you need one more yield outside the loop.

 print(list(dns_split(s)))
> ['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '']
> 
> It'll gag on nested brackets (fixable with a counter) and has no
> error handling (requires thought), but it's a start.
 
Something similar on top of regex:

>>> def split(s):
... start = level = 0
... for m in re.compile(r"[[:\]]").finditer(s):
... if m.group() == "[": level += 1
... elif m.group() == "]":
... assert level
... level -= 1
... elif level == 0:
... yield s[start:m.start()]
... start = m.end()
... yield s[start:]
... 
>>> list(split("a[b:c:]:d"))
['a[b:c:]', 'd']
>>> list(split("a[b:c[:]]:d"))
['a[b:c[:]]', 'd']
>>> list(split(""))
['']
>>> list(split(":"))
['', '']
>>> list(split(":x"))
['', 'x']
>>> list(split("[:x]"))
['[:x]']
>>> list(split(":[:x]"))
['', '[:x]']
>>> list(split(":[:[:]:x]"))
['', '[:[:]:x]']
>>> list(split("[:::]"))
['[:::]']
>>> s = "foo.[DOM]::[IP6::4361:6368:6574]:600::"
>>> list(split(s))
['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']

Note that there is one more empty string which I believe the OP forgot.

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


Re: String splitting with exceptions

2013-08-28 Thread Neil Cerutti
On 2013-08-28, Tim Chase  wrote:
> On 2013-08-28 13:14, random...@fastmail.us wrote:
>> On Wed, Aug 28, 2013, at 12:44, John Levine wrote:
>> > I have a crufty old DNS provisioning system that I'm rewriting
>> > and I hope improving in python.  (It's based on tinydns if you
>> > know what that is.)
>> > 
>> > The record formats are, in the worst case, like this:
>> > 
>> > foo.[DOM]::[IP6::4361:6368:6574]:600::
>> 
>> Otherwise:
>> >>> re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
>> ['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']
>> 
>> I'm not sure why _your_ list only has one empty string at the end.
>
> I wondered that.

Good point. My little parser fails on that, too. It'll miss *all*
final fields. My parser needs "if s: yield s[b:]" at the end, to
operate like str.split, where the empty string is special.

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


Re: String splitting with exceptions

2013-08-28 Thread Neil Cerutti
On 2013-08-28, John Levine  wrote:
> I have a crufty old DNS provisioning system that I'm rewriting and I
> hope improving in python.  (It's based on tinydns if you know what
> that is.)
>
> The record formats are, in the worst case, like this:
>
> foo.[DOM]::[IP6::4361:6368:6574]:600::
>
> What I would like to do is to split this string into a list like this:
>
> [ 'foo.[DOM]','','[IP6::4361:6368:6574]','600','' ]
>
> Colons are separators except when they're inside square
> brackets.  I have been messing around with re.split() and
> re.findall() and haven't been able to come up with either a
> working separator pattern for split() or a working field
> pattern for findall().  I came pretty close with findall() but
> can't get it to reliably match the nothing between two adjacent
> colons not inside brackets.
>
> Any suggestions? I realize I could do it in a loop where I pick
> stuff off the front of the string, but yuck.

A little parser, as Skip suggested, is a good way to go.

The brackets make your string context-sensitive, a difficult
concept to cleanly parse with a regex.

I initially hoped a csv module dialect could work, but the quote
character is (currently) hard-coded to be a single, simple
character, i.e., I can't tell it to treat [xxx] as "xxx".

What about Skip's suggestion? A little parser. It might seem
crass or something, but it really is easier than musceling a
regex into a context sensitive grammer.

def dns_split(s):
in_brackets = False
b = 0 # index of beginning of current string
for i, c in enumerate(s):
if not in_brackets:
if c == "[":
in_brackets = True
elif c == ':':
yield s[b:i]
b = i+1
elif c == "]":
in_brackets = False

>>> print(list(dns_split(s)))
['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '']

It'll gag on nested brackets (fixable with a counter) and has no
error handling (requires thought), but it's a start.

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


Re: can't get utf8 / unicode strings from embedded python

2013-08-28 Thread David M. Cotter
Thank you for your thoughtful and thorough response.  I now understand much 
better what you (and apparently the others) were warning me against and I will 
certainly consider that moving forward.

I very much appreciate your help as I learn about python and embedding and all 
these crazy encoding problems.

> What do kids have to do with this?
When a person has children, they quickly learn that the best way to deal with 
some one who seems to be not listening or having a tantrum: show understanding 
and compassion, restraint and patience, as you, in the most neutral way that 
you can, gently bit firmly guide said person back on track.  You learn that if 
you instead express your frustration at said person, that it never, ever helps 
the situation, and only causes more hurt to be spread around to the very people 
you are ostensibly attempting to help.

> Are you an adult or a child?
Perhaps my comment was lost in translation, but this is rather the question 
that I was obliquely asking you.  *wink right back*

In any case I thank you for your help, which has in fact been quite great!  My 
demo script is working, and I know now to properly advise my script writers 
regarding how to properly encode strings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String splitting with exceptions

2013-08-28 Thread Tim Chase
On 2013-08-28 13:14, random...@fastmail.us wrote:
> On Wed, Aug 28, 2013, at 12:44, John Levine wrote:
> > I have a crufty old DNS provisioning system that I'm rewriting
> > and I hope improving in python.  (It's based on tinydns if you
> > know what that is.)
> > 
> > The record formats are, in the worst case, like this:
> > 
> > foo.[DOM]::[IP6::4361:6368:6574]:600::
> 
> Otherwise:
> >>> re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
> ['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']
> 
> I'm not sure why _your_ list only has one empty string at the end.

I wondered that.  I also wondered about bracketed quoting that
doesn't start at the beginning of a field:

  foo.[one:two]::[IP6::1234:5678:9101]:600::
  ^
This might be bogus, or one might want to catch this case.

-tkc

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


Re: String splitting with exceptions

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 12:44, John Levine wrote:
> I have a crufty old DNS provisioning system that I'm rewriting and I
> hope improving in python.  (It's based on tinydns if you know what
> that is.)
> 
> The record formats are, in the worst case, like this:
> 
> foo.[DOM]::[IP6::4361:6368:6574]:600::
> 
> What I would like to do is to split this string into a list like this:
> 
> [ 'foo.[DOM]','','[IP6::4361:6368:6574]','600','' ]
> 
> Colons are separators except when they're inside square brackets.  I
> have been messing around with re.split() and re.findall() and haven't
> been able to come up with either a working separator pattern for
> split() or a working field pattern for findall().  I came pretty
> close with findall() but can't get it to reliably match the
> nothing between two adjacent colons not inside brackets.
> 
> Any suggestions? I realize I could do it in a loop where I pick stuff
> off the front of the string, but yuck.
> 
> This is in python 2.7.5.

Can you have brackets within brackets? If so, this is impossible to deal
with within a regex.

Otherwise:
>>> re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']

I'm not sure why _your_ list only has one empty string at the end. Is
the record always terminated by a colon that is not meant to imply an
empty field after it? If so, remove the question mark:

>>> re.findall('((?:[^[:]|\[[^]]*\])*):',s)
['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '']

I've done this kind of thing (for validation, not capturing) for email
addresses (there are some obscure bits of email address syntax that need
it) before, so it came to mind immediately.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String splitting with exceptions

2013-08-28 Thread Skip Montanaro
> The record formats are, in the worst case, like this:
>
> foo.[DOM]::[IP6::4361:6368:6574]:600::

> Any suggestions?

Write a little parser that can handle the record format?

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


String splitting with exceptions

2013-08-28 Thread John Levine
I have a crufty old DNS provisioning system that I'm rewriting and I
hope improving in python.  (It's based on tinydns if you know what
that is.)

The record formats are, in the worst case, like this:

foo.[DOM]::[IP6::4361:6368:6574]:600::

What I would like to do is to split this string into a list like this:

[ 'foo.[DOM]','','[IP6::4361:6368:6574]','600','' ]

Colons are separators except when they're inside square brackets.  I
have been messing around with re.split() and re.findall() and haven't
been able to come up with either a working separator pattern for
split() or a working field pattern for findall().  I came pretty
close with findall() but can't get it to reliably match the
nothing between two adjacent colons not inside brackets.

Any suggestions? I realize I could do it in a loop where I pick stuff
off the front of the string, but yuck.

This is in python 2.7.5.

-- 
Regards,
John Levine, jo...@iecc.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. http://jl.ly
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3 integer division debugging

2013-08-28 Thread Neal Becker
Chris Angelico wrote:

> On Thu, Aug 29, 2013 at 1:21 AM, Oscar Benjamin
>  wrote:
>> On 28 August 2013 16:15, Neal Becker  wrote:
>>> The change in integer division seems to be the most insidious source of
>>> silent errors in porting code from python2 - since it changes the behaviour
>>> or valid code silently.
>>>
>>> I wish the interpreter had an instrumented mode to detect and report such
>>> problems.
>>
>> Is that a joke?
>>
>> Run the code under Python 2.6/2.7 with the -3 flag:
> 
> I wouldn't say that's a joke, it's just another demonstration of
> Guido's time machine :)
> 
> ChrisA

Ah!  I looked for it in python3.  Funny it isn't there as well.  Thanks!

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


Re: python3 integer division debugging

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 1:21 AM, Oscar Benjamin
 wrote:
> On 28 August 2013 16:15, Neal Becker  wrote:
>> The change in integer division seems to be the most insidious source of 
>> silent
>> errors in porting code from python2 - since it changes the behaviour or valid
>> code silently.
>>
>> I wish the interpreter had an instrumented mode to detect and report such
>> problems.
>
> Is that a joke?
>
> Run the code under Python 2.6/2.7 with the -3 flag:

I wouldn't say that's a joke, it's just another demonstration of
Guido's time machine :)

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


Re: python3 integer division debugging

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 11:15, Neal Becker wrote:
> The change in integer division seems to be the most insidious source of
> silent 
> errors in porting code from python2 - since it changes the behaviour or
> valid 
> code silently.
> 
> I wish the interpreter had an instrumented mode to detect and report such 
> problems.

There is such a mode in python2 from version 2.2 through 2.7: -Q warn.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3 integer division debugging

2013-08-28 Thread Oscar Benjamin
On 28 August 2013 16:15, Neal Becker  wrote:
> The change in integer division seems to be the most insidious source of silent
> errors in porting code from python2 - since it changes the behaviour or valid
> code silently.
>
> I wish the interpreter had an instrumented mode to detect and report such
> problems.

Is that a joke?

Run the code under Python 2.6/2.7 with the -3 flag:

$ cat test.py

print(10 / 7)

$ python -3 test.py
test.py:2: DeprecationWarning: classic int division
  print(10 / 7)
1


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


python3 integer division debugging

2013-08-28 Thread Neal Becker
The change in integer division seems to be the most insidious source of silent 
errors in porting code from python2 - since it changes the behaviour or valid 
code silently.

I wish the interpreter had an instrumented mode to detect and report such 
problems.

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


Re: Improving the web page download code.

2013-08-28 Thread MRAB

On 28/08/2013 07:23, mukesh tiwari wrote:
[snip]

Initially I blocked the main using raw_input('') and it was working fine.

u = Downloader()
signal.signal( signal.SIGINT , u.handleexception)
thread.start_new_thread ( u.createurl , () )
for i in xrange ( 5 ) :
 thread.start_new_thread ( u.downloadurl , () )
#This is for blocking main
raw_input('')
When I pressed  ctrl-c then it's responding fine but now after switching to 
threading module, I am not able to kill my program using SIGINT ( ctrl-c ). Any 
idea how to signal SIGINT to threads ?

Try making them daemon threads. A daemon thread is one that will be 
killed when the main thread terminates.



Now the changed code and I have to catch the SIGINT.
 u = Downloader()
 signal.signal( signal.SIGINT , u.handleexception)
 urlcreator = threading.Thread ( target = u.createurl )

 workers = []
 for i in xrange ( 5 ):
 workers.append ( threading.Thread( target = u.downloadurl ) )


   urlcreator.daemon = True

 urlcreator.start()



 for w in workers:

   urlcreator.daemon = True
   w.daemon = True

 w.start()

 urlcreator.join()
 for w in workers:
 w.join()



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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 4:38:02 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt 
έγραψε:
> Am 28.08.2013 13:55, schrieb Ferrous Cranus:
> 
> > Τη Τετάρτη, 28 Αυγούστου 2013 2:32:44 μ.μ. UTC+3, ο χρήστης Dave Angel 
> > έγραψε:
> 
> >> You really have no directory in which you have write permissions?  If
> 
> >> so, perhaps  you'd better solve that first.
> 
> >
> 
> >
> 
> > of cours ei ahve write permissions. Here:
> 
> >
> 
> > ni...@superhost.gr [~]# ls -ld www/
> 
> > drwxr-x--- 4 nikos nobody 4096 Jul 13 10:33 www//
> 
> > ni...@superhost.gr [~]# ls -ld www/cgi-bin/
> 
> > drwxr-xr-x 2 nikos nikos 4096 Aug 28 10:41 www/cgi-bin//
> 
> >
> 
> >
> 
> > whick make it a mysterya s to why
> 
> > with open("../err.out", "a") as f:
> 
>  > fails to write the file.
> 
> 
> 
> ...maybe it's because the server is not running as user nikos?
> 
> 
> 
> Uli

Yes Uli, the script metrits.py is being invoked by Apache Web Server which in 
turn runs under user Nobody.
So, that mean that? user 'nobody' has no write permission to /home/nikos folder?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ulrich Eckhardt

Am 28.08.2013 13:55, schrieb Ferrous Cranus:

Τη Τετάρτη, 28 Αυγούστου 2013 2:32:44 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:

You really have no directory in which you have write permissions?  If
so, perhaps  you'd better solve that first.



of cours ei ahve write permissions. Here:

ni...@superhost.gr [~]# ls -ld www/
drwxr-x--- 4 nikos nobody 4096 Jul 13 10:33 www//
ni...@superhost.gr [~]# ls -ld www/cgi-bin/
drwxr-xr-x 2 nikos nikos 4096 Aug 28 10:41 www/cgi-bin//


whick make it a mysterya s to why
with open("../err.out", "a") as f:

> fails to write the file.

...maybe it's because the server is not running as user nikos?

Uli

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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
W dniu środa, 28 sierpnia 2013 15:43:39 UTC+2 użytkownik Tim Chase napisał:
 
> When 3 replies from 3 people all arrive within minutes, each
> suggesting reduce(), I'd figure it's the "one obvious way to do 
> it" :-)

I guess it's at least a good hint ;)


Thanks to all! :)


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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Tim Chase
On 2013-08-28 06:23, AdamKal wrote:
> Thanks! 
> 
> I guess this is as simple as it gets then. I was just looking for
> the "one obvious way to do it".

When 3 replies from 3 people all arrive within minutes, each
suggesting reduce(), I'd figure it's the "one obvious way to do
it" :-)

-tkc



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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Chris Angelico
On Wed, Aug 28, 2013 at 11:23 PM, AdamKal  wrote:
> I guess this is as simple as it gets then. I was just looking for the "one 
> obvious way to do it".

The one obvious way to do some things is to post on python-list and
see what comes back :) I love reading over these sorts of threads,
they're good fun.

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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Thomas Rachel

Am 2013-08-28 14:52 schrieb AdamKal:

Hi,

 From time to time I have to apply a series of functions to a value in such a 
way:

func4(func3(func2(func1(myval

I was wondering if there is a function in standard library that would take a 
list of functions and a initial value and do the above like this:

func_im_looking_for([func1, func2, func3, func4], myval)

I looked in itertools but nothing seamed to do the job. This seams like 
something vary obvious that was needed many times elsewhere so maybe you could 
help me?


reduce(lambda x, f: f(x), funcs, myval)

would do the job.


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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
Thanks! 

I guess this is as simple as it gets then. I was just looking for the "one 
obvious way to do it".

W dniu środa, 28 sierpnia 2013 15:11:34 UTC+2 użytkownik Tim Chase napisał:
> On 2013-08-28 05:52, AdamKal wrote:
> 
> > From time to time I have to apply a series of functions to a value
> 
> > in such a way:
> 
> > 
> 
> > func4(func3(func2(func1(myval
> 
> > 
> 
> > I was wondering if there is a function in standard library that
> 
> > would take a list of functions and a initial value and do the above
> 
> > like this:
> 
> > 
> 
> > func_im_looking_for([func1, func2, func3, func4], myval)
> 
> 
> 
> At least in Py2.x you can use reduce:
> 
> 
> 
>   reduce(lambda value, fn: fn(value), [list_of_functions], myval)
> 
> 
> 
> I believe it was moved into functools.reduce() in Py3.x meaning you
> 
> might want to do something like
> 
> 
> 
>   try:
> 
> reduce # see if it's already in __builtins__
> 
>   except NameError: # running Py3...
> 
> from functools import reduce
> 
> 
> 
> or
> 
> 
> 
>   try:
> 
> from functools import reduce
> 
>   except ImportError:
> 
> pass  # it should already be in __builtins__ for pre-2.6
> 
> 
> 
> at the top to make sure it's in your global namespace.
> 
> 
> 
> -tkc

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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Jussi Piitulainen
Tim Chase writes:

> On 2013-08-28 05:52, AdamKal wrote:
> > From time to time I have to apply a series of functions to a value
> > in such a way:
> > 
> > func4(func3(func2(func1(myval
> > 
> > I was wondering if there is a function in standard library that
> > would take a list of functions and a initial value and do the above
> > like this:
> > 
> > func_im_looking_for([func1, func2, func3, func4], myval)
> 
> At least in Py2.x you can use reduce:
> 
>   reduce(lambda value, fn: fn(value), [list_of_functions], myval)

I notice now that I didn't notice, when I just sent the same solution,
that the function list was already backwards to its intended order of
application, so yes, this should work as wanted.

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


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread ishish

Am 28.08.2013 13:52, schrieb AdamKal:

Hi,

From time to time I have to apply a series of functions to a value in
such a way:

func4(func3(func2(func1(myval

I was wondering if there is a function in standard library that would
take a list of functions and a initial value and do the above like
this:

func_im_looking_for([func1, func2, func3, func4], myval)

I looked in itertools but nothing seamed to do the job. This seams
like something vary obvious that was needed many times elsewhere so
maybe you could help me?


You could try somthing like:


myval = 'whatever'

for i in range(1,4):
print eval("func%s(%s)" % (i, myval))
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Jussi Piitulainen
AdamKal writes:

> Hi, 
> 
> From time to time I have to apply a series of functions to a value
> in such a way:
> 
> func4(func3(func2(func1(myval
> 
> I was wondering if there is a function in standard library that
> would take a list of functions and a initial value and do the above
> like this:
> 
> func_im_looking_for([func1, func2, func3, func4], myval)
> 
> I looked in itertools but nothing seamed to do the job. This seams
> like something vary obvious that was needed many times elsewhere so
> maybe you could help me?

If you can have things backwards, or have func_im_looking_for reverse
things first, you can do it this way:

from functools import reduce

def funcall(arg, fun): return fun(arg)

def func1(arg): return 'f1({})'.format(arg)
def func2(arg): return 'f2({})'.format(arg)
def func3(arg): return 'f3({})'.format(arg)

# prints: f1(f2(f3(3.14)))
print(reduce(funcall, (func3, func2, func1), 3.14))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
This si what iam tryign now since the function ishish proposed wont help me.


try:
  #find the needed counter for the page URL
  if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
  cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
  data = cur.fetchone() #URL is unique, so should only be one
except:
  print( repr(e) )


[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Original exception 
was:
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Traceback (most 
recent call last):
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 174, in 
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] 
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]   File 
"/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 
108, in execute
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] query = query % 
escaped_args
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] TypeError: 
unsupported operand type(s) for %: 'bytes' and 'str'
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] 
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] During handling of 
the above exception, another exception occurred:
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] 
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Traceback (most 
recent call last):
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 177, in 
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print( repr(e) )
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] NameError: name 'e' 
is not defined
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Tim Chase
On 2013-08-28 05:52, AdamKal wrote:
> From time to time I have to apply a series of functions to a value
> in such a way:
> 
> func4(func3(func2(func1(myval
> 
> I was wondering if there is a function in standard library that
> would take a list of functions and a initial value and do the above
> like this:
> 
> func_im_looking_for([func1, func2, func3, func4], myval)

At least in Py2.x you can use reduce:

  reduce(lambda value, fn: fn(value), [list_of_functions], myval)

I believe it was moved into functools.reduce() in Py3.x meaning you
might want to do something like

  try:
reduce # see if it's already in __builtins__
  except NameError: # running Py3...
from functools import reduce

or

  try:
from functools import reduce
  except ImportError:
pass  # it should already be in __builtins__ for pre-2.6

at the top to make sure it's in your global namespace.

-tkc



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


My attempts in playing with tail-recursion in python

2013-08-28 Thread Thomas Baruchel
Hi,

I would like to share some of my recent attempts concerning recursivity in
python, more precisely recursivity with lambda functions.

I know that the title of my thread with the "tail-recursion" words may wake up
some long and old war; please don't take it as such. I am not claiming anything
about what programming languages should be or not; I enjoy using python for
many purposes and I perfectly know how to handle loops for achieving some tasks,
but sometimes I like rather think with recursivity because I have been using
various dialects of Lisp for a long time. I had a very great time studying the
Y-combinator; then I wrote various pieces of code for remapping recursive calls
to loop iterations.

The following functions are fully usable; I hope someone will enjoy using them.
If you are not interested by the explanations, just jump to the end of the
message and take my functions for using them.

Here is a recursive function:
  fac = lambda f: lambda n: 1 if n==0 else n*f(n-1)
The Y-combinator is well known:
  Y = lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))

Now, you can use the recursive function:
  rf = Y(fac)
  rf(5)

Now we write fac as a tail-recursive function:
  fac = lambda f: lambda a,b: b if a==0 else f(a-1,a*b)
  rf = Y(fac)
  rf(5,1)
but of course, the recursivity is handled like previously.

In fact, it is very easy to build some effcient wrapper; for instance:
  (lambda f: f(lambda *args: ("callback",args)))
will act in the following way:
  (lambda f: f(lambda *args: ("callback",args)))(fac)(5,1)
 --> ('callback', (4, 5))
  (lambda f: f(lambda *args: ("callback",args)))(fac)(4,5)
 --> ('callback', (3, 20))
  (lambda f: f(lambda *args: ("callback",args)))(fac)(3,20))
 --> ('callback', (2, 60))
  (lambda f: f(lambda *args: ("callback",args)))(fac)(2,60)
 --> ('callback', (1, 120))
  (lambda f: f(lambda *args: ("callback",args)))(fac)(1,120)
 --> ('callback', (0, 120))
  (lambda f: f(lambda *args: ("callback",args)))(fac)(0,120)
 --> 120
Here, the "callback" string is arbitrary chosen in order to make the loop know
that a next call is needed.

Now, the recursivity is handled as successive calls, which is what I was looking
for. A first proposal could be:

  def with_tail_recursion(func):
x = (lambda f: f(lambda *args: ("callback",args)))(func)
def wrapper(*args):
  out = ("callback",args)
  while type(out)==tuple and out[0]=="callback":
out = x(*out[1])
  return out
return wrapper

Now, the very same function can be used as recursive or inside a loop:
  fac = lambda f: lambda a,b: b if a==0 else f(a-1,a*b)
  rf = Y(fac)
  tr = with_tail_recursion(fac)
  rf(5,1)
 --> 120
  tr(5,1)
 --> 120

Of course, if most of your job relies on writing functions returning tuples
with the string "callback" being the first argument, you should use another
keyword in the previous code ;-)

You can inspect the stack by raising an exception:
  f2 = lambda f: lambda n: 1/n if n==0 else f(n-1)
and see the differences between Y(f2)(5) and with_tail_recursion(f2)(5)

But I was not fully happy with the use of a tuple, efficient but a little too
tricky to my eyes. For that reason, I took the Y combinator again and slightly
modified it:

  lambda f: (lambda x: x(x))(lambda y: f(lambda *args: lambda: y(y)(*args)))

Now, the function doesn't call itself, but returns a function calling itself
with the relevant arguments.

I like this new function better than the previous one, but it is now more
difficult for the wrapper to detect when it is time to leave the loop.
Right now, I use the following test: checking for the __call__ string in
the dir() list. This means ONE IMPORTANT THING: this second wrapper can't
handle tail-recursive functions returning functions, (which is actually more
likely to happen than tail-recursive functions returning tuples with the
string "callback" being the first argument ;-) ). But I like it that way:

  def B(func):
x = (lambda f: (lambda x: x(x))(lambda y:
  f(lambda *args: lambda: y(y)(*args(func)
def wrapper(*args):
  out = x(*args)
  while '__call__' in dir(out):
out = out()
  return out
return wrapper

tr2 = B(fac)
tr2(5,1)
  --> 120

Now, you can write functions with a huge depth of recusivity with no
problem :
  B(lambda f: lambda n: "ok" if n==0 else f(n-1))(5000)
(don't try with the Y combinator instead...)

Best regards,

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


Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
Hi, 

>From time to time I have to apply a series of functions to a value in such a 
>way:

func4(func3(func2(func1(myval

I was wondering if there is a function in standard library that would take a 
list of functions and a initial value and do the above like this:

func_im_looking_for([func1, func2, func3, func4], myval)

I looked in itertools but nothing seamed to do the job. This seams like 
something vary obvious that was needed many times elsewhere so maybe you could 
help me?

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 3:38:11 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Wed, 28 Aug 2013 05:17:34 -0700, Ferrous Cranus wrote:
> 
> 
> 
> > As i have pointed out i as the owner of the accoutn have read and write
> 
> > perimssion bot at www/ and www/cgi-bin i also chnage the filename and
> 
> > still cant write to the file.
> 
> 
> 
> If you type filenames as carelessly as you type requests for help, who 
> 
> knows what file name you are actually trying to open?
> 
> 
> 
> Or to put it another way...
> 
> 
> 
> If yuo tpye filnaems as carlesl yas y outype reqets for help, woh knwos 
> 
> wha tfile nmae oyu ar eactaly tying to oep n?
> 
> 
> 
> 
> 
> Nikos, my Greek is completely non-existent, and I admire you for learning 
> 
> a second language. I know your English is good, because I have seen you 
> 
> write fluent, excellent English. But if you can't be bothered to type 
> 
> carefully and clearly when asking questions, then how can you expect 
> 
> others to be bothered to read and respond to your questions?
> 
> 
> 
> 
> 
> > if you as experts cannot help resolve this, how me as a newbiw can?
> 
> 
> 
> Just because your account has write permission to a location doesn't mean 
> 
> that the script being run by the webserver has write permission. You need 
> 
> to write to a location where the script has permission to write. First 
> 
> you need to find out what account the script is being run under -- it may 
> 
> be "apache", or possible "nobody", but I don't know. It shouldn't be 
> 
> "root", and almost certainly isn't "nikos". I'm not an expert, but a few 
> 
> seconds googling came up with a lot of useful looking hits. Google on 
> 
> "what user does apache run as" and do your research.
> 
> 
> 
> This is off-topic though. This is not a "beginner's guide to apache" 
> 
> forum, if you can't solve this problem yourself you'll have to take it 
> 
> elsewhere.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Hi steven , sorry for the typos.

you are write my script is invoked by apache web server application which it 
runs under account 'nobody'

Here is proof of that:

ni...@superhost.gr [~]# ps aux | grep Apache
nikos 8531  0.0  0.0   6372   680 pts/0R+   12:44   0:00 grep Apache
ni...@superhost.gr [~]# ps aux | grep apache
root  1101  0.0  0.2  65576  4168 ?Ss   08:30   0:01 
/usr/local/apache/bin/httpd -k start -DSSL
root  8448  0.0  0.1  65576  1700 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8449  0.0  0.2  65712  3228 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8450  0.0  0.2  65848  3348 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8451  0.0  0.2  65848  3360 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8452  0.0  0.2  65712  3340 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8453  0.0  0.2  65712  3260 ?S12:42   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8467  0.0  0.1  65712  2356 ?S12:43   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8468  0.0  0.1  65712  2344 ?S12:43   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nobody8519  0.0  0.1  65712  2344 ?S12:43   0:00 
/usr/local/apache/bin/httpd -k start -DSSL
nikos 8537  0.0  0.0   6372   684 pts/0R+   12:44   0:00 grep apache

My script were all workign in the previous VPS enviroment, the script is 
correct is just a few minor thing in the new VPS env that they need to be taken 
care of thus prohibit my script to run..

please don't give up helping me and tell me please what you want me to try.
tahnk you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split lines from stdin into a list of unicode strings

2013-08-28 Thread kurt . alfred . mueller
On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote:
> On 28/8/2013 04:32, Kurt Mueller wrote:
> > For some text manipulation tasks I need a template to split lines
> > from stdin into a list of strings the way shlex.split() does it.
> > The encoding of the input can vary.

> Does that mean it'll vary from one run of the program to the next, or
> it'll vary from one line to the next?  Your code below assumes the
> latter.  That can greatly increase the unreliability of the already
> dubious chardet algorithm.

The encoding only varies from one launch to the other.
The reason I process each line is memory usage.

Option to have a better reliability of chardet:
I could read all of the input, save the input lines for further
processing in a list, feed the lines into
chardet.universaldetector.UniversalDetector.feed()/close()/result()
and then decode and split/shlex the lines in the list.
That way the chardet oracle would be more reliable, but 
roughly twice as much memory will be used.


> > import chardet
> Is this the one ?
> https://pypi.python.org/pypi/chardet

Yes.

> > $ cat  | template.py

> Why not have a separate filter that converts from a (guessed) encoding
> into utf-8, and have the later stage(s)  assume utf-8 ?  That way, the
> filter could be fed clues by the user, or replaced entirely, without
> affecting the main code you're working on.

Working on UNIX-like systems (I am happy to work in a MSFZ)
the processing pipe would be then:

cat  | recode2utf8 | splitlines.py
memory usage 2 *  ( plus chardet memory usage )


> Alternatively, just add a commandline argument with the encoding, and
> parse it into enco_type.

cat  | splitlines.py -e latin9
memory usage 1 * 

or

cat  | splitlines.py -e $( codingdetect  )
memory usage 1 * 

So, because memory usage is not primary,
I think I will go with the option described above.


-- 
Kurt Müller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 05:17:34 -0700, Ferrous Cranus wrote:

> As i have pointed out i as the owner of the accoutn have read and write
> perimssion bot at www/ and www/cgi-bin i also chnage the filename and
> still cant write to the file.

If you type filenames as carelessly as you type requests for help, who 
knows what file name you are actually trying to open?

Or to put it another way...

If yuo tpye filnaems as carlesl yas y outype reqets for help, woh knwos 
wha tfile nmae oyu ar eactaly tying to oep n?


Nikos, my Greek is completely non-existent, and I admire you for learning 
a second language. I know your English is good, because I have seen you 
write fluent, excellent English. But if you can't be bothered to type 
carefully and clearly when asking questions, then how can you expect 
others to be bothered to read and respond to your questions?


> if you as experts cannot help resolve this, how me as a newbiw can?

Just because your account has write permission to a location doesn't mean 
that the script being run by the webserver has write permission. You need 
to write to a location where the script has permission to write. First 
you need to find out what account the script is being run under -- it may 
be "apache", or possible "nobody", but I don't know. It shouldn't be 
"root", and almost certainly isn't "nikos". I'm not an expert, but a few 
seconds googling came up with a lot of useful looking hits. Google on 
"what user does apache run as" and do your research.

This is off-topic though. This is not a "beginner's guide to apache" 
forum, if you can't solve this problem yourself you'll have to take it 
elsewhere.



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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 3:21:25 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Wed, 28 Aug 2013 03:43:08 -0700, Ferrous Cranus wrote:
> 
> 
> 
> > but i cannot see the error_log because of constant scrolling of error
> 
> > output.
> 
> 
> 
> Then don't use "tail -F", use "less".
> 
> 
> 
> Or try "tail -s 60 -F" which will update only every 60 seconds.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Very nice idea, than k you steven. Less work withiut scrilling like hell liek 
tail -F did.

this is what i have now:


# Exception Identification 
def formatExceptionInfo(maxTBlevel=5): 
cla, exc, trbk = sys.exc_info() 
excName = cla.__name__ 
try: 
excArgs = exc.__dict__["args"] 
except KeyError: 
excArgs = "" 
excTb = traceback.format_tb(trbk, maxTBlevel) 
return (excName, excArgs, excTb) 

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()   #URL is unique, so should only be one
except:
print( formatExceptionInfo() )

i see no error on what it used ot be isnteait comain at the follwing line which 
is:

if not data:
#first time for page; primary key is automatic, hit is 
defaulted
cur.execute('''INSERT INTO counters (url) VALUES 
(%s)''', page )
cID = cur.lastrowid#get the primary key value 
of the new record 
else:
#found the page, save primary key and use it to issue 
hit UPDATE 
cID = data[0]
cur.execute('''UPDATE counters SET hits = hits + 1 
WHERE ID = %s''', cID )


i jst dont follow. What ishsi proposed supposed to give us the error in the 
query bit now it tells difefrent things.

shoudl i remove the function since it want any helopfull?


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


Re: New VPS Provider needed

2013-08-28 Thread Antoon Pardon
Op 28-08-13 13:25, Steven D'Aprano schreef:
> On Wed, 28 Aug 2013 09:19:40 +0200, Antoon Pardon wrote:
> 
>> Op 27-08-13 18:18, Steven D'Aprano schreef:
>>> On Wed, 28 Aug 2013 00:41:17 +1000, Chris Angelico wrote:
>>>
 On Wed, Aug 28, 2013 at 12:25 AM, Grant Edwards
  wrote:
> On 2013-08-27,   wrote:
>
>> Iam having major issues with my VPS provider and losign customers
>> becaue the provider doesnt set thign u[ cprrectly.
>
> Perhaps he's also having problems with a faulty keyboard.

 Just a faulty key actuator, I think. Nothing unusual in this world.
>>>
>>>
>>> Guys, PLEASE stop baiting Nikos with snide remarks. It makes this a
>>> very unpleasant environment, and sets the tone of the community, badly.
>>
>> Why don't you tell Nikos he should stop baiting the list with off topic
>> requestsm like whether someone is willing to provide him free hosting?
> 
> I quote:
> 
> 1. I will pay for a full year upfront but it must be a low price 
> for the 1st year, because i have already paid them and cant get my
> money back to use it to the new com opany.

You are quoting selectively.

> I get it. You don't like Nikos. I'm not suggesting you should. But 
> misrepresenting him is Not Cool. He has offered to pay.

IMO you are misrepresenting by quoting selectively. This from earlier
in that same post:

| So, if someone want to help me out it would be nice if he could
| provide me with services free of charge for that time period, or at
| least at the end of they year.

That he offered to pay, doesn't contradict his primary request is for
services free of charge.

> Besides, Python-friendly web hosting is not off-topic. Plenty of people 
> have asked for recommendations on hosting providers that support Python 
> before.

He didn't ask for people experiences with various hosting providers. He
was asking people here to provide hosting services for him.

>> I also think you are over reacting. One thread where people come with
>> snide remarks doesn't turn the whole newsgroup/mailinglist into an
>> unpleasant environment.
> 
> My wife often tells me it is a miracle that I don't forget my own name, 
> but even my memory is not so bad as to forget just how unpleasant and 
> hostile this list became a month or so ago when a whole bunch of people 
> decided to drive Nikos away, and he decided to fight back.

This list didn't became unpleasand and hostile. The hostility was
contained to a few threads. It was easy enough to avoid the hostility
if that was important enough to you.

I also find your reporting on the facts misleading. People didn't just
decide to drive Nikos away. People were getting fed up with the ongoing
annoying behaviour of Nikos. It wasn't Nikos who decided to fight back,
it were the people who had enough of Nikos's inconsiderate behaviour
who decided to fight back.

-- 
Antoon Pardon

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


Re: Why is str(None) == 'None' and not an empty string?

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 01:57:16 -0700, Piotr Dobrogost wrote:

> Hi!
> 
> Having repr(None) == 'None' is sure the right thing but why does
> str(None) == 'None'? Wouldn't it be more correct if it was an empty
> string?


Why do you think an empty string is more correct? Would you expect
str([]) or str(0.0) or str({}) to also give an empty string?


I can't see any reason for str(None) to return the empty string.



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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 03:43:08 -0700, Ferrous Cranus wrote:

> but i cannot see the error_log because of constant scrolling of error
> output.

Then don't use "tail -F", use "less".

Or try "tail -s 60 -F" which will update only every 60 seconds.



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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 3:11:07 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Wed, 28 Aug 2013 01:46:01 -0700, Ferrous Cranus wrote:
> 
> 
> 
> > Τη Τρίτη, 27 Αυγούστου 2013 8:07:52 μ.μ. UTC+3, ο χρήστης Steven
> 
> > D'Aprano έγραψε:
> 
> 
> 
> >> Hint: you can use
> 
> >> "print(type(page), file=open('path/to/some/file', 'w'))"
> 
> >> 
> 
> >> to see the type of the variable 'page' without displaying it on your
> 
> >> website.
> 
> 
> 
> 
> 
> > i tried to do what you said and iam receing this:
> 
> > 
> 
> > [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120] Original
> 
> > exception was: [Wed Aug 28 08:43:31 2013] [error] [client
> 
> > 108.162.231.120] Traceback (most recent call last): [Wed Aug 28 08:43:31
> 
> > 2013] [error] [client 108.162.231.120]   File
> 
> > "/home/nikos/public_html/cgi-bin/metrites.py", line 39, in  [Wed
> 
> > Aug 28 08:43:31 2013] [error] [client 108.162.231.120] print(
> 
> > type(page), file=open('../err.out', 'w') ) [Wed Aug 28 08:43:31 2013]
> 
> > [error] [client 108.162.231.120] PermissionError: [Errno 13]
> 
> > \\u0386\\u03c1\\u03bd\\u03b7\\u03c3\\u03b7
> 
> > \\u03c0\\u03c1\\u03cc\\u03c3\\u03b2\\u03b1\\u03c3\\u03b7\\u03c2:
> 
> > '../err.out' [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120]
> 
> > Premature end of script headers: metrites.py
> 
> 
> 
> Then pick a different location, one where you have permission to write 
> 
> files!
> 
> 
> 
> Honestly Nikos, I'm not trying to be rude, but if you cannot think of 
> 
> this on your own after all this time we've been helping you, perhaps 
> 
> programming is not the right vocation for you. Perhaps you need to 
> 
> consider a change of career.
> 
> 
> 
> If you do decide to stay as a web developer, you need to start thinking:
> 
> 
> 
> * What is this error message telling me? ("Permission denied")
> 
> 
> 
> * How can I fix that? ("I need permission to read the file. Maybe try a 
> 
> different file?")
> 
> 
> 
> 
> 
> 
> 
> > Also many times when i try to view the error_log by
> 
> > 
> 
> > tail -F /usr/local/apache/logs/error_log &
> 
> > 
> 
> > i get realtime scrolling of other joomla webistes pho errors and i have
> 
> > hard time trackign my own webistes erros.
> 
> > 
> 
> > is ther a work around for that?
> 
> 
> 
> 
> 
> That's an apache logging issue, not Python, and I don't know enough about 
> 
> apache to do more than guess that there probably is a solution but I have 
> 
> no idea what it is.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

As i have pointed out i as the owner of the accoutn have read and write 
perimssion bot at www/ and www/cgi-bin
i also chnage the filename and still cant write to the file.

if you as experts cannot help resolve this, how me as a newbiw can?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread ishish

Well there you have it:

  File "/home/nikos/public_html/cgi-bin/metrites.py", line 191, in 


if not data:
NameError: name 'data' is not defined

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 01:46:01 -0700, Ferrous Cranus wrote:

> Τη Τρίτη, 27 Αυγούστου 2013 8:07:52 μ.μ. UTC+3, ο χρήστης Steven
> D'Aprano έγραψε:

>> Hint: you can use
>> "print(type(page), file=open('path/to/some/file', 'w'))"
>> 
>> to see the type of the variable 'page' without displaying it on your
>> website.


> i tried to do what you said and iam receing this:
> 
> [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120] Original
> exception was: [Wed Aug 28 08:43:31 2013] [error] [client
> 108.162.231.120] Traceback (most recent call last): [Wed Aug 28 08:43:31
> 2013] [error] [client 108.162.231.120]   File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 39, in  [Wed
> Aug 28 08:43:31 2013] [error] [client 108.162.231.120] print(
> type(page), file=open('../err.out', 'w') ) [Wed Aug 28 08:43:31 2013]
> [error] [client 108.162.231.120] PermissionError: [Errno 13]
> \\u0386\\u03c1\\u03bd\\u03b7\\u03c3\\u03b7
> \\u03c0\\u03c1\\u03cc\\u03c3\\u03b2\\u03b1\\u03c3\\u03b7\\u03c2:
> '../err.out' [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120]
> Premature end of script headers: metrites.py

Then pick a different location, one where you have permission to write 
files!

Honestly Nikos, I'm not trying to be rude, but if you cannot think of 
this on your own after all this time we've been helping you, perhaps 
programming is not the right vocation for you. Perhaps you need to 
consider a change of career.

If you do decide to stay as a web developer, you need to start thinking:

* What is this error message telling me? ("Permission denied")

* How can I fix that? ("I need permission to read the file. Maybe try a 
different file?")



> Also many times when i try to view the error_log by
> 
> tail -F /usr/local/apache/logs/error_log &
> 
> i get realtime scrolling of other joomla webistes pho errors and i have
> hard time trackign my own webistes erros.
> 
> is ther a work around for that?


That's an apache logging issue, not Python, and I don't know enough about 
apache to do more than guess that there probably is a solution but I have 
no idea what it is.



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


Re: can't get utf8 / unicode strings from embedded python

2013-08-28 Thread Steven D'Aprano
On Tue, 27 Aug 2013 22:57:45 -0700, David M. Cotter wrote:

> I am very sorry that I have offended you to such a degree you feel it
> necessary to publicly eviscerate me.

You know David, you are right. I did over-react. And I apologise for 
that. I am sorry, I was excessively confrontational. (Although I think 
"eviscerate" is a bit strong.)

Putting aside my earlier sarcasm, the basic message remains the same: 
Python byte strings are not designed to work with Unicode characters, and 
if they do work, it is an accident, not defined behaviour.


> Perhaps I could have worded it like this:  "So far I have not seen any
> troubles including unicode characters in my strings, they *seem* to be
> fine for my use-case.  What kind of trouble has been seen with this by
> others?"

Exactly the same sort of trouble you were having earlier when you were 
inadvertently decoding the source file as MacRoman rather than UTF-8. 
Mojibake, garbage characters in your text, corrupted data.

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


The point is, you might not see these errors, because by accident all the 
relevant factors conspire to give you the correct result. You might test 
it on a Mac and on Windows and it all works well. You might even test it 
on a dozen different machines, and it works fine on all of them. But 
since you're relying on an accident of implementation, none of this is 
guaranteed. And then in eighteen months time, *something* changes -- a 
minor update to Python, a different version of Mac OS/X, an unusual 
Registry setting in Windows, who knows what?, and all of a sudden the 
factors no longer line up to give you the correct results and it all 
comes tumbling down in a big stinking mess. If you are lucky you will get 
a nice clear exception telling you something is broken, but more likely 
you'll just get corrupted data and mojibake and you, or the poor guy who 
maintains the code after you, will have no idea why. And you'll probably 
come here asking for our help to solve it.

If you came back and said "I tried it with the u prefix, and it broke a 
bunch of other code, and I don't have time to fix it now so I'm reverting 
to the u-less byte string form" I wouldn't *like* it but I could *accept* 
it as one of those sub-optimal compromises people make in Real Life. I've 
done the same thing myself, we probably all have: written code we knew 
was broken, but fixing it was too hard or too low a priority.


> Really, I wonder why you are so angry at me for having made a mistake? 
> I'm going to guess that you don't have kids.

What do kids have to do with this? Are you an adult or a child? *wink*

You didn't offend me so much as frustrate me. You had multiple people 
telling you the same thing, don't embed Unicode characters in a byte 
string, but you choose to not just ignore them but effectively declare 
that they were all wrong to give that advice, not just the people here 
but essentially the entire Python development community responsible for 
adding Unicode strings to the language. Can you blame me for feeling that 
your reply seemed rather arrogant?

In any case, I'm glad you responded with a little more restraint than I 
did, and I hope you can see my point of view and hopefully I haven't 
soured you on this forum.


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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 2:51:03 μ.μ. UTC+3, ο χρήστης ishish έγραψε:
> Am 28.08.2013 12:14, schrieb Ferrous Cranus:
> 
> > Okey, continue trying and trying i came up with this:
> 
> >
> 
> >
> 
> > try:
> 
> > if os.path.exists( path + page ) or os.path.exists( cgi_path + page 
> 
> > ):
> 
> > cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
> 
> > data = cur.fetchone()
> 
> > except:
> 
> > with open("err.out", "a") as f:
> 
> > f.write( repr(query), type(query) )
> 
> > f.write( repr(escaped_args), type(escaped_args) )
> 
> >
> 
> >
> 
> > But i cannot test it without looking at the error log which is
> 
> > scrolling like hell and doesn't even quit with a ctrl+c
> 
> >
> 
> > How will i manage to troubleshoot?
> 
> > Please confirm the above is correct and is what you were propsoing i
> 
> > shoudl test.
> 
> 
> 
> A simple way I always use if it comes to exception handling:
> 
> 
> 
> import sys
> 
> import traceback
> 
> 
> 
> # Exception Identification
> 
> def formatExceptionInfo(maxTBlevel=5):
> 
>   cla, exc, trbk = sys.exc_info()
> 
>   excName = cla.__name__
> 
>   try:
> 
>   excArgs = exc.__dict__["args"]
> 
>   except KeyError:
> 
>   excArgs = ""
> 
>   excTb = traceback.format_tb(trbk, maxTBlevel)
> 
>   return (excName, excArgs, excTb)
> 
> 
> 
> try:
> 
>   # Your code
> 
> except:
> 
>   print formatExceptionInfo()

ni...@superhost.gr [~/www]# [Wed Aug 28 12:02:53 2013] [error] [client 
108.162.231.120] malformed header from script. Bad header= 
'index.html': metrites.py
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Error in 
sys.excepthook:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] ValueError: 
underlying buffer has been detached
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120]
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Original exception 
was:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Traceback (most 
recent call last):
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 191, in 
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] if not data:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] NameError: name 
'data' is not defined
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] File does not 
exist: /home/nikos/public_html/500.shtml
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 2:32:44 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:
> On 28/8/2013 07:14, Ferrous Cranus wrote:
> 
> 
> 
> >
> 
> >
> 
> > But i cannot test it without looking at the error log which is scrolling 
> > like hell and doesn't even quit with a ctrl+c
> 
> 
> 
> I take it this 'error log" is shared with other users, and you can't
> 
> constrain them to cease and desist for a while?
> 
> 
> 
> >
> 
> > How will i manage to troubleshoot?
> 
> > Please confirm the above is correct and is what you were propsoing i shoudl 
> > test.
> 
> 
> 
> You really have no directory in which you have write permissions?  If
> 
> so, perhaps  you'd better solve that first.


of cours ei ahve write permissions. Here:

ni...@superhost.gr [~]# ls -ld www/
drwxr-x--- 4 nikos nobody 4096 Jul 13 10:33 www//
ni...@superhost.gr [~]# ls -ld www/cgi-bin/
drwxr-xr-x 2 nikos nikos 4096 Aug 28 10:41 www/cgi-bin//


whick make it a mysterya s to why
with open("../err.out", "a") as f: 

fails to write the file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread ishish

Am 28.08.2013 12:14, schrieb Ferrous Cranus:

Okey, continue trying and trying i came up with this:


try:
if os.path.exists( path + page ) or os.path.exists( cgi_path + page 
):

cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()
except:
with open("err.out", "a") as f:
f.write( repr(query), type(query) )
f.write( repr(escaped_args), type(escaped_args) )


But i cannot test it without looking at the error log which is
scrolling like hell and doesn't even quit with a ctrl+c

How will i manage to troubleshoot?
Please confirm the above is correct and is what you were propsoing i
shoudl test.


A simple way I always use if it comes to exception handling:

import sys
import traceback

# Exception Identification
def formatExceptionInfo(maxTBlevel=5):
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
try:
excArgs = exc.__dict__["args"]
except KeyError:
excArgs = ""
excTb = traceback.format_tb(trbk, maxTBlevel)
return (excName, excArgs, excTb)

try:
# Your code
except:
print formatExceptionInfo()
--
http://mail.python.org/mailman/listinfo/python-list


Rép : Why is str(None) == 'None' and not an empty string?

2013-08-28 Thread Fabrice POMBET

On 8/28/2013 4:57 AM, Piotr Dobrogost wrote:

> Having repr(None) == 'None' is sure the right thing but why does str(None) == 
> 'None'? Wouldn't it be more correct if it was an empty string?

the point of str(obj) is to return a string containing the obj (a sequence of 
characters if it is unbound or not built-in, etc.)...

If you set the rule str(None)=="", then you will cause plenty of problems. 

For instance, if you want to build a string like request="SELECT X"+"IN 
Y"+"WHERE B="+String(B)
to prepare a sequel request, and the field B happens to be sometimes "None", 
you would automatically end up with """SELECT X IN Y WHERE B=''""" instead of 
"""SELECT X IN Y WHERE B='None'""",
and your sql request will fall into limbos...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 2:32:44 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:
> On 28/8/2013 07:14, Ferrous Cranus wrote:
> 
> 
> 
> >
> 
> >
> 
> > But i cannot test it without looking at the error log which is scrolling 
> > like hell and doesn't even quit with a ctrl+c
> 
> 
> 
> I take it this 'error log" is shared with other users, and you can't
> 
> constrain them to cease and desist for a while?
> 
> 
> 
> >
> 
> > How will i manage to troubleshoot?
> 
> > Please confirm the above is correct and is what you were propsoing i shoudl 
> > test.
> 
> 
> 
> You really have no directory in which you have write permissions?  If
> 
> so, perhaps  you'd better solve that first.
> 
> 
> 
> 
> 
> -- 
> 
> DaveA



[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] Error in 
sys.excepthook:
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] ValueError: 
underlying buffer has been detached
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] Original exception 
was:
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] Traceback (most 
recent call last):
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.  
  py", line 173, in 
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] 
cur.execute('''SELECT ID FROM counters WHERE
 url = %s''', page )
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]   File 
"/usr/local/bin/python/lib/python3.3/site-  
  packages/pymysql/cursors.py", line 
108, in execute
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] query = query % 
escaped_args
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] TypeError: 
unsupported operand type(s) for %: 'by  
  tes' and 'str'
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] During handling of 
the above exception, another e  
  xception occurred:
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] Traceback (most 
recent call last):
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.  
  py", line 176, in 
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] with 
open("err.out", "a") as f:
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] PermissionError: 
[Errno 13] \\u0386\\u03c1\\u03bd
\\u03b7\\u03c3\\u03b7 
\\u03c0\\u03c1\\u03cc\\u03c3\\u03b2\\u03b1\\u03c3\\u03b7\\u03c2: 'err.out'
[Wed Aug 28 11:34:36 2013] [error] [client 108.162.231.120] File does not 
exist: /home/nikos/public_html/500. 
   shtml
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 2:32:44 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:
> On 28/8/2013 07:14, Ferrous Cranus wrote:
> 
> 
> 
> >
> 
> >
> 
> > But i cannot test it without looking at the error log which is scrolling 
> > like hell and doesn't even quit with a ctrl+c
> 
> 
> 
> I take it this 'error log" is shared with other users, and you can't
> 
> constrain them to cease and desist for a while?
> 
> 
> 
> >
> 
> > How will i manage to troubleshoot?
> 
> > Please confirm the above is correct and is what you were propsoing i shoudl 
> > test.
> 
> 
> 
> You really have no directory in which you have write permissions?  If
> 
> so, perhaps  you'd better solve that first.


hello Dave,

no this is the general error log apache produces for all the server.

Is there a way to grep error logging info, pertainign only to my specific nikos 
account or my superhost.gr domain?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Dave Angel
On 28/8/2013 07:14, Ferrous Cranus wrote:

>
>
> But i cannot test it without looking at the error log which is scrolling like 
> hell and doesn't even quit with a ctrl+c

I take it this 'error log" is shared with other users, and you can't
constrain them to cease and desist for a while?

>
> How will i manage to troubleshoot?
> Please confirm the above is correct and is what you were propsoing i shoudl 
> test.

You really have no directory in which you have write permissions?  If
so, perhaps  you'd better solve that first.


-- 
DaveA

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


Re: New VPS Provider needed

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 09:19:40 +0200, Antoon Pardon wrote:

> Op 27-08-13 18:18, Steven D'Aprano schreef:
>> On Wed, 28 Aug 2013 00:41:17 +1000, Chris Angelico wrote:
>> 
>>> On Wed, Aug 28, 2013 at 12:25 AM, Grant Edwards
>>>  wrote:
 On 2013-08-27,   wrote:

> Iam having major issues with my VPS provider and losign customers
> becaue the provider doesnt set thign u[ cprrectly.

 Perhaps he's also having problems with a faulty keyboard.
>>>
>>> Just a faulty key actuator, I think. Nothing unusual in this world.
>> 
>> 
>> Guys, PLEASE stop baiting Nikos with snide remarks. It makes this a
>> very unpleasant environment, and sets the tone of the community, badly.
> 
> Why don't you tell Nikos he should stop baiting the list with off topic
> requestsm like whether someone is willing to provide him free hosting?

I quote:

1. I will pay for a full year upfront but it must be a low price 
for the 1st year, because i have already paid them and cant get my
money back to use it to the new com opany.

I get it. You don't like Nikos. I'm not suggesting you should. But 
misrepresenting him is Not Cool. He has offered to pay.

Besides, Python-friendly web hosting is not off-topic. Plenty of people 
have asked for recommendations on hosting providers that support Python 
before.


> I also think you are over reacting. One thread where people come with
> snide remarks doesn't turn the whole newsgroup/mailinglist into an
> unpleasant environment.

My wife often tells me it is a miracle that I don't forget my own name, 
but even my memory is not so bad as to forget just how unpleasant and 
hostile this list became a month or so ago when a whole bunch of people 
decided to drive Nikos away, and he decided to fight back.


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


Re: right adjusted strings containing umlauts

2013-08-28 Thread kurt . alfred . mueller
On Wednesday, August 28, 2013 12:23:12 PM UTC+2, Dave Angel wrote:
> On 28/8/2013 04:01, Kurt Mueller wrote:
> > Because I cannot switch to Python 3 for now my life is not so easy:-)
> > For some text manipulation tasks I need a template to split lines
> > from stdin into a list of strings the way shlex.split() does it.
> > The encoding of the input can vary.
> > For further processing in Python I need the list of strings to be in 
> > unicode.
> According to:
>http://docs.python.org/2/library/shlex.html
> """Prior to Python 2.7.3, this module did not support Unicode
> input"""
> I take that to mean that if you upgrade to Python 2.7.3, 2.7.4, or
> 2.7.5, you'll have Unicode support.

I have Python 2.7.3

> Presumably that would mean you could decode the string before calling
> shlex.split().

Yes, see new template.py:
###
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# split lines from stdin into a list of unicode strings
# decode before shlex
# Muk 2013-08-28
# Python 2.7.3

from __future__ import print_function
import sys
import shlex
import chardet

bool_cmnt = True  # shlex: skip comments
bool_posx = True  # shlex: posix mode (strings in quotes)

for inpt_line in sys.stdin:
print( 'inpt_line=' + repr( inpt_line ) )
enco_type = chardet.detect( inpt_line )[ 'encoding' ]   # 
{'encoding': 'EUC-JP', 'confidence': 0.99}
print( 'enco_type=' + repr( enco_type ) )
strg_unic = inpt_line.decode( enco_type )   # decode 
the input line into unicode
print( 'strg_unic=' + repr( strg_unic ) )   # unicode 
input line
try:
strg_inpt = shlex.split( strg_unic, bool_cmnt, bool_posx, ) # check if 
shlex works on unicode
except Exception, errr: # usually 
'No closing quotation'
print( "error='%s' on inpt_line='%s'" % ( errr, inpt_line.rstrip(), ), 
file=sys.stderr, )
continue
print( 'strg_inpt=' + repr( strg_inpt ) )   # list of 
strings

###

$ python -V
Python 2.7.3
$ echo -e "a b c d e\na Ö u 1 2" | template.py
inpt_line='a b c d e\n'
enco_type='ascii'
strg_unic=u'a b c d e\n'
strg_inpt=['a', 'b', 'c', 'd', 'e']
inpt_line='a \xc3\x96 u 1 2\n'
enco_type='utf-8'
strg_unic=u'a \xd6 u 1 2\n'
error=''ascii' codec can't encode character u'\xd6' in position 2: ordinal not 
in range(128)' on inpt_line='a Ö u 1 2'
$ echo -e "a b c d e\na Ö u 1 2" | recode utf8..latin9 | 
./split_shlex_unicode.py 
inpt_line='a b c d e\n'
enco_type='ascii'
strg_unic=u'a b c d e\n'
strg_inpt=['a', 'b', 'c', 'd', 'e']
inpt_line='a \xd6 u 1 2\n'
enco_type='windows-1252'
strg_unic=u'a \xd6 u 1 2\n'
error=''ascii' codec can't encode character u'\xd6' in position 2: ordinal not 
in range(128)' on inpt_line='a � u 1 2'
$

As can be seen, shlex does work only with unicode strings decoded from 'ascii' 
strings. (Python 2.7.3)

-- 
Kurt Müller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus

Okey, continue trying and trying i came up with this:


try:
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()
except:
with open("err.out", "a") as f:
f.write( repr(query), type(query) )
f.write( repr(escaped_args), type(escaped_args) )


But i cannot test it without looking at the error log which is scrolling like 
hell and doesn't even quit with a ctrl+c

How will i manage to troubleshoot?
Please confirm the above is correct and is what you were propsoing i shoudl 
test.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split lines from stdin into a list of unicode strings

2013-08-28 Thread Dave Angel
On 28/8/2013 04:32, Kurt Mueller wrote:

> This is a follow up to the Subject
> "right adjusted strings containing umlauts"

You started a new thread, with a new subject line.  So presumably we're
starting over with a clean slate.

>
> For some text manipulation tasks I need a template to split lines
> from stdin into a list of strings the way shlex.split() does it.
> The encoding of the input can vary.

Does that mean it'll vary from one run of the program to the next, or
it'll vary from one line to the next?  Your code below assumes the
latter.  That can greatly increase the unreliability of the already
dubious chardet algorithm.

> For further processing in Python I need the list of strings to be in unicode.
>
> Here is template.py:
>
> ##
> #!/usr/bin/env python
> # vim: set fileencoding=utf-8 :
> # split lines from stdin into a list of unicode strings
> # Muk 2013-08-23
> # Python 2.7.3
>
> from __future__ import print_function
> import sys
> import shlex
> import chardet

Is this the one ?
https://pypi.python.org/pypi/chardet

>
> bool_cmnt = True  # shlex: skip comments
> bool_posx = True  # shlex: posix mode (strings in quotes)
>
> for inpt_line in sys.stdin:
> print( 'inpt_line=' + repr( inpt_line ) )
> enco_type = chardet.detect( inpt_line )[ 'encoding' ]   # 
> {'encoding': 'EUC-JP', 'confidence': 0.99}
> print( 'enco_type=' + repr( enco_type ) )
> try:
> strg_inpt = shlex.split( inpt_line, bool_cmnt, bool_posx, ) # shlex 
> does not work on unicode

But shlex does, since you're using Python 2.7.3

> except Exception, errr: # usually 
> 'No closing quotation'
> print( "error='%s' on inpt_line='%s'" % ( errr, inpt_line.rstrip(), 
> ), file=sys.stderr, )
> continue
> print( 'strg_inpt=' + repr( strg_inpt ) )   # list of 
> strings
> strg_unic = [ strg.decode( enco_type ) for strg in strg_inpt ]  # decode 
> the strings into unicode
> print( 'strg_unic=' + repr( strg_unic ) )   # list of 
> unicode strings
> ##
>
> $ cat  | template.py
>

Why not have a separate filter that converts from a (guessed) encoding
into utf-8, and have the later stage(s)  assume utf-8 ?  That way, the
filter could be fed clues by the user, or replaced entirely, without
affecting the main code you're working on.

Alternatively, just add a commandline argument with the encoding, and
parse it into enco_type.


-- 
DaveA


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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 1:11:05 μ.μ. UTC+3, ο χρήστης ishish έγραψε:

> http://wiki.python.org/moin/HandlingExceptions

is this how you mean?

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( 
cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE 
url = %s''', page )
data = cur.fetchone()   #URL is unique, 
so should only be one
except:
print repr(query) 
print type(query) 

print repr(escaped_args) 
print type(escaped_args)


but i cannot see the error_log because of constant scrolling of error output.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τετάρτη, 28 Αυγούστου 2013 1:43:08 μ.μ. UTC+3, ο χρήστης Ferrous Cranus 
έγραψε:
> Τη Τετάρτη, 28 Αυγούστου 2013 1:11:05 μ.μ. UTC+3, ο χρήστης ishish έγραψε:
> 
> 
> 
> > http://wiki.python.org/moin/HandlingExceptions
> 
> 
> 
> is this how you mean?
> 
> 
> 
>   try:
> 
>   #find the needed counter for the page URL
> 
>   if os.path.exists( path + page ) or os.path.exists( 
> cgi_path + page ):
> 
>   cur.execute('''SELECT ID FROM counters WHERE 
> url = %s''', page )
> 
>   data = cur.fetchone()   #URL is unique, 
> so should only be one
> 
>   except:
> 
>   print repr(query) 
> 
>   print type(query) 
> 
> 
> 
>   print repr(escaped_args) 
> 
>   print type(escaped_args)
> 
> 
> 
> 
> 
> but i cannot see the error_log because of constant scrolling of error output.

i try: tail -F /usr/local/apache/logs/error_log | grep nikos &'

and see the follwing. if i dont grep at all i cannot stop the eroor output:

i...@superhost.gr [~]# [Wed Aug 28 10:44:22 2013] [error] [client 
108.162.231.120]   File "/home/nikos/public_html/cgi-bin/metrites.py", line 
173, in 
[Wed Aug 28 10:44:22 2013] [error] [client 108.162.231.120]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 176, in 
[Wed Aug 28 10:44:22 2013] [error] [client 108.162.231.120] File does not 
exist: /home/nikos/public_html/500.shtml
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: right adjusted strings containing umlauts

2013-08-28 Thread Dave Angel
On 28/8/2013 04:01, Kurt Mueller wrote:


> Because I cannot switch to Python 3 for now my life is not so easy:-)
>
> For some text manipulation tasks I need a template to split lines
> from stdin into a list of strings the way shlex.split() does it.
> The encoding of the input can vary.
> For further processing in Python I need the list of strings to be in unicode.
>

According to:
   http://docs.python.org/2/library/shlex.html

"""Prior to Python 2.7.3, this module did not support Unicode
input"""

I take that to mean that if you upgrade to Python 2.7.3, 2.7.4, or
2.7.5, you'll have Unicode support.

Presumably that would mean you could decode the string before calling
shlex.split().

-- 
DaveA


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


Re: Why is str(None) == 'None' and not an empty string?

2013-08-28 Thread Terry Reedy

On 8/28/2013 4:57 AM, Piotr Dobrogost wrote:


Having repr(None) == 'None' is sure the right thing but why does str(None) == 
'None'? Wouldn't it be more correct if it was an empty string?


No.
There is no reason to be different.

--
Terry Jan Reedy

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


about pyyaml questions!

2013-08-28 Thread Thanatos xiao
Hi Guys:
   Now I use pyyaml to load a yaml file, after I dump this load data,but I
found an questions,before I load the yaml file,the file looks like:


-
   -b
   -c
-
   -e
   -x

after I dump this data and write file, the file looks like:

-  -b
   -c
-  -e
   -x

although when dump file, I have set default_flow_style=False

Can the dumped file the same as original file?

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


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread ishish

Am 28.08.2013 10:48, schrieb Ferrous Cranus:

>> I quote from a Python 3 Guide

>> [http://python.about.com/od/python30/ss/30_strings_3.htm]:

>>

>> The two data types, str and bytes, are mutually exclusive. One

>> cannot

>> legally combine them into one call. With the distinction between

>> text

>> and data, therefore, comes the need to convert between them.

>>

>>

>

> So, in this line:

>

> cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )

>

> the variable 'page' needs conversion to what?

>

> all that is stores is the location of a file

>

> path = '/home/nikos/public_html/'

>

> page = form.getvalue('page')

>

> if not page and os.path.exists( file ):

> # it is an html template

> page = file.replace( path, '' )

>

> So chnage it to what?

> --

> What is now proved was at first only imagined!





The error occurs in file


"/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py",

line 108, in execute

query = query % escaped_args



You can check the actual values and data types using:



print repr(query)

print type(query)



print repr(escaped_args)

print type(escaped_args)



Always useful is a proper exception handling using try:/except:



hOW YOU MEAN PLEASE I TRY TO IMPLMENT WHAT YOU PROPOSE BUT I CANT.

try:
#find the needed counter for the page URL
		if os.path.exists( path + page ) or os.path.exists( cgi_path + page 
):

cur.execute('''SELECT ID FROM counters WHERE url = 
%s''', page )
data = cur.fetchone()   #URL is unique, so 
should only be one


print repr('''SELECT ID FROM counters WHERE url = %s''')
print type('''SELECT ID FROM counters WHERE url = %s''')

print repr(escaped_args)
print type(escaped_args)

I MEAN IF FAILS BEFORE IT TRIES TO GO INTO MY PRINT STAEMNT.
HOW AM I GONNA CPATURE THE QUERY?



http://i.stack.imgur.com/jiFfM.jpg

http://wiki.python.org/moin/HandlingExceptions
--
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
Τη Τρίτη, 27 Αυγούστου 2013 6:22:32 μ.μ. UTC+3, ο χρήστης ishish έγραψε:
> Am 27.08.2013 16:04, schrieb Ferrous Cranus:
> 
> > Στις 27/8/2013 4:59 μμ, ο/η ishish έγραψε:
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Error 
> 
> >>> in
> 
> >>> sys.excepthook:
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]
> 
> >>> ValueError: underlying buffer has been detached
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] 
> 
> >>> Original
> 
> >>> exception was:
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] 
> 
> >>> Traceback
> 
> >>> (most recent call last):
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]   File
> 
> >>> "/home/nikos/public_html/cgi-bin/metrites.py", line 169, in 
> 
> >>> 
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]
> 
> >>> cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]   File
> 
> >>>
> 
> >>> 
> 
> >>> "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py",
> 
> >>> line 108, in execute
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] 
> 
> >>> query
> 
> >>> = query % escaped_args
> 
> >>> [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189]
> 
> >>> TypeError: unsupported operand type(s) for %: 'bytes' and 'str'
> 
> >>
> 
> >> I quote from a Python 3 Guide
> 
> >> [http://python.about.com/od/python30/ss/30_strings_3.htm]:
> 
> >>
> 
> >> The two data types, str and bytes, are mutually exclusive. One 
> 
> >> cannot
> 
> >> legally combine them into one call. With the distinction between 
> 
> >> text
> 
> >> and data, therefore, comes the need to convert between them.
> 
> >>
> 
> >>
> 
> >
> 
> > So, in this line:
> 
> >
> 
> > cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
> 
> >
> 
> > the variable 'page' needs conversion to what?
> 
> >
> 
> > all that is stores is the location of a file
> 
> >
> 
> > path = '/home/nikos/public_html/'
> 
> >
> 
> > page = form.getvalue('page')
> 
> >
> 
> > if not page and os.path.exists( file ):
> 
> > # it is an html template
> 
> > page = file.replace( path, '' )
> 
> >
> 
> > So chnage it to what?
> 
> > --
> 
> > What is now proved was at first only imagined!
> 
> 
> 
> 
> 
> The error occurs in file 
> 
> "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", 
> 
> line 108, in execute
> 
> query = query % escaped_args
> 
> 
> 
> You can check the actual values and data types using:
> 
> 
> 
> print repr(query)
> 
> print type(query)
> 
> 
> 
> print repr(escaped_args)
> 
> print type(escaped_args)
> 
> 
> 
> Always useful is a proper exception handling using try:/except:


hOW YOU MEAN PLEASE I TRY TO IMPLMENT WHAT YOU PROPOSE BUT I CANT.

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + 
page ):
cur.execute('''SELECT ID FROM counters WHERE url = 
%s''', page )
data = cur.fetchone()   #URL is unique, so 
should only be one


print repr('''SELECT ID FROM counters WHERE url = %s''') 
print type('''SELECT ID FROM counters WHERE url = %s''') 

print repr(escaped_args) 
print type(escaped_args) 

I MEAN IF FAILS BEFORE IT TRIES TO GO INTO MY PRINT STAEMNT.
HOW AM I GONNA CPATURE THE QUERY?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Ferrous Cranus
In my attemtpt to be shwon only mesages pertaining to superhost.gr i try:

alias err='tail -F /usr/local/apache/logs/error_log | grep nikos &'

but now it only displays to me the lines that have '/home/nikos' within them 
and not all the relevant error lines.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Improving the web page download code.

2013-08-28 Thread Alister
On Tue, 27 Aug 2013 12:41:10 -0700, mukesh tiwari wrote:

> Hello All,
> I am doing web stuff first time in python so I am looking for
> suggestions. I wrote this code to download the title of webpages using
> as much less resource ( server time, data download)  as possible and
> should be fast enough. Initially I used BeautifulSoup for parsing but
> the person who is going to use this code asked me not to use this and
> use regular expressions ( The reason was BeautifulSoup is not fast
> enough ? ).

By the time you have written enough RE to reliably parse HTML(I ma not 
sure that that is even strictly possible) you will have re-inverted 
BeautifullSoup, Badly. unless you are looking for a very explicit section 
of data in the page this is not a good idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >