[newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
Hello

I'm an amateur programmer, and would like to know what the main
options are to build web applications in Python instead of PHP.

I notice that Python-based solutions are usually built as long-running
processes with their own web server (or can run in the back with eg.
Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a
language to write scripts and requires a web server (short running
processes).

Since web scripts are usually very short anyway (user sends query,
server handles request, sends response, and closes the port) because
the user is waiting and browsers usually give up after 30 seconds
anyway... why did Python solutions go for long-running processes while
PHP was built from the start as short-running processes?

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Alain Ketterlin
Gilles  writes:

> I notice that Python-based solutions are usually built as long-running
> processes with their own web server (or can run in the back with eg.
> Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a
> language to write scripts and requires a web server (short running
> processes).

It's an artefact of the server infrastructure, there is no rule here.
Any solution used with one language could be used with the other.

> Since web scripts are usually very short anyway (user sends query,
> server handles request, sends response, and closes the port) because
> the user is waiting and browsers usually give up after 30 seconds
> anyway... why did Python solutions go for long-running processes while
> PHP was built from the start as short-running processes?

You misunderstand the problem here. It's not about the duration of the
actions, it's about the latency it takes to read/parse/execute the
script. HTTP is stateless anyway, so if the same "interpreter" handles
several requests, what you save by keeping the interpreter alive is the
load/parse phase. If you relaunch an interpreter for every HTTP request,
you pay the same price again and again for something which is not even
related to your scripts' execution.

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Chris Angelico
On Tue, Jun 12, 2012 at 7:39 PM, Gilles  wrote:
> Since web scripts are usually very short anyway (user sends query,
> server handles request, sends response, and closes the port) because
> the user is waiting and browsers usually give up after 30 seconds
> anyway... why did Python solutions go for long-running processes while
> PHP was built from the start as short-running processes?

Think of it as Apache + PHP versus Python. Apache keeps running, it's
only your PHP script that starts and stops. With a long-running
process, you keep everything all in together, which IMHO is simpler
and better.

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 12:12:55 +0200, Alain Ketterlin
 wrote:
>You misunderstand the problem here. It's not about the duration of the
>actions, it's about the latency it takes to read/parse/execute the
>script. HTTP is stateless anyway, so if the same "interpreter" handles
>several requests, what you save by keeping the interpreter alive is the
>load/parse phase. If you relaunch an interpreter for every HTTP request,
>you pay the same price again and again for something which is not even
>related to your scripts' execution.

Thanks for the input.

But I read that PHP-based heavy-duty web servers compile the scripts
once and keep them in a cache, so they don't have to be
read/parsed/executed with each new query.

In that case, what is the benefit of using a long-running process in
Python?

I enjoy writing scripts in Python much more than PHP, but with so many
sites written in PHP, I need to know what major benefits there are in
choosing Python (or Ruby, ie. not PHP).

Apparently, very few people use Python à la PHP, ie. Python code
embedded in web pages?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Octavian Rasnita
From: "Chris Angelico" 
Subject: Re: [newbie] Equivalent to PHP?


> On Tue, Jun 12, 2012 at 7:39 PM, Gilles  wrote:
>> Since web scripts are usually very short anyway (user sends query,
>> server handles request, sends response, and closes the port) because
>> the user is waiting and browsers usually give up after 30 seconds
>> anyway... why did Python solutions go for long-running processes while
>> PHP was built from the start as short-running processes?


Perl, Ruby, Python and PHP also can do the same thing.

You can use a persistent program which is loaded/parsed/compiled once and kept 
into memory and it will just answer the requests, or you can create a program 
which is loaded/parsed/compiled on each request.

The first way is much better for performance reasons but it consumes much more 
memory and it is more complicated, because the programs can have memory leaks 
(they will consume more and more memory after a long period), while the second 
way is more simple to do, but the performance is not great.

Most PHP programs are done using the second way, because it is much simple to 
do and it is much simple to configure the environment for it, and most of the 
free web hosting sites that offer PHP support don't offer something better.
And... most of the sites don't need a very good performance, because they 
usually don't have millions visitors per day.

Also, most of the sites made in PHP use low level programs using only what the 
default PHP distribution installed on the server offers, so no web frameworks, 
or form managers, or templating systems or many other modules that can do a 
part of the work.
The PHP distribution has compiled C programs which run pretty fast, while 
loading/parsing/compiling a lot of other modules made in Ruby/Perl/Python/PHP 
would decrease the performance, so a persistent environment is usually required 
in case those modules are used. And usually Python and Perl and Ruby programs 
use a lot of modules because for these languages there are a lot of modules 
available that can do a lot of things for free, while for PHP there are much 
fewer, and even if there are, (because there are templating systems and web 
frameworks for PHP also), they are much seldomly used, because those who choose 
to use a broken language like PHP, usually choose it not only for its main 
advantage regarding the easiness of deployment, but choose it because it is 
much more simple and easy to learn, and they usually don't like to learn a lot 
of other modules.
Otherwise... if you want you can also create a web app using PHP and 
CodeIgniter web framework and run it with fastcgi...

Octavian

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread D'Arcy Cain

On 12-06-12 06:36 AM, Gilles wrote:

I enjoy writing scripts in Python much more than PHP, but with so many
sites written in PHP, I need to know what major benefits there are in
choosing Python (or Ruby, ie. not PHP).


I think that you just answered your own question in the first line of
that paragraph.  With computers running so fast and memory and disk
being so cheap, the only decision left for most applications is what
language do you prefer.  Python wins because it is so nice to work
with.  It's clean and you don't have to deal with the daily security
holes of PHP.


Apparently, very few people use Python à la PHP, ie. Python code
embedded in web pages?


I guess I am in the minority then.  I do plan to turn one of my larger
projects into a standalone web server some day but so far writing
simple Python CGI scripts has served me fine.  I even do some embedding
by using server side scripting.

--
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Chris Angelico
On Tue, Jun 12, 2012 at 8:36 PM, Gilles  wrote:
> Thanks for the input.
>
> But I read that PHP-based heavy-duty web servers compile the scripts
> once and keep them in a cache, so they don't have to be
> read/parsed/executed with each new query.
>
> In that case, what is the benefit of using a long-running process in
> Python?

Apache's mod_php partially evens out the difference, but not
completely, and of course, it's perfectly possible to write a dispatch
loop in PHP, as Octavian said.

Python is a far better language than PHP, I would strongly recommend
making use of it if you can.

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Matej Cepl

On 12/06/12 11:39, Gilles wrote:

I notice that Python-based solutions are usually built as long-running
processes with their own web server (or can run in the back with eg.
Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a
language to write scripts and requires a web server (short running
processes).


I don't think it is a proper description of the situation (please, 
somebody correct my mistakes, I am not 100% sure about it myself). WSGI 
applications (which is basically all web applications in Python) could 
run in the hosted servers (using for example mod_wsgi for Apache), and I 
would expect that it is the situation with most production uses.


From the programmer's point of view WSGI application (read 
http://en.wikipedia.org/wiki/Wsgi) is just one script which takes HTTP 
request on input and generates HTTP Response on output, so it is 
actually quite simple. And actually quite similar to what JSGI, PSGI, 
and Rake do (I am not sure who was first whether WSGI or Rake).



anyway... why did Python solutions go for long-running processes while
PHP was built from the start as short-running processes?


It is all about caching ... I am not sure how it  is done exactly, but I 
would expect for example mod_wsgi to cache parsed Python script in 
memory as well.


Matěj
--
http://mail.python.org/mailman/listinfo/python-list


using identifiers before they are defined

2012-06-12 Thread Julio Sergio
I'm puzzled with the following example, which is intended to be a part of a 
module, say "tst.py":

  a = something(5)

  def something(i):
  return i



When I try: 

->>> import tst

The interpreter cries out:

Traceback (most recent call last):
  File "", line 1, in 
  File "tst.py", line 11, in 
a = something(5)
NameError: name 'something' is not defined

I know that changing the order of the definitions will work, however there are 
situations in which referring to an identifier before it is defined is 
necessary, e.g., in crossed recursion. 

So I modified my module:

  global something

  a = something(5)


  def something(i):
  return i


And this was the answer I got from the interpreter:

->>> import tst

Traceback (most recent call last):
  File "", line 1, in 
  File "tst.py", line 12, in 
a = something(5)
NameError: global name 'something' is not defined


Do you have any comments?

Thanks,

--Sergio.




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


Re: using identifiers before they are defined

2012-06-12 Thread Jose H. Martinez
You should define the function first and then call it.


 def something(i):
 return i

a = something(5)

If you want a reference to the function somewhere else you can do this:

global alias = something

print alias(i)



On Tue, Jun 12, 2012 at 1:53 PM, Julio Sergio  wrote:

> I'm puzzled with the following example, which is intended to be a part of a
> module, say "tst.py":
>
>  a = something(5)
>
>  def something(i):
>  return i
>
>
>
> When I try:
>
> ->>> import tst
>
> The interpreter cries out:
>
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "tst.py", line 11, in 
>a = something(5)
> NameError: name 'something' is not defined
>
> I know that changing the order of the definitions will work, however there
> are
> situations in which referring to an identifier before it is defined is
> necessary, e.g., in crossed recursion.
>
> So I modified my module:
>
>  global something
>
>  a = something(5)
>
>
>  def something(i):
>  return i
>
>
> And this was the answer I got from the interpreter:
>
> ->>> import tst
>
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "tst.py", line 12, in 
>a = something(5)
> NameError: global name 'something' is not defined
>
>
> Do you have any comments?
>
> Thanks,
>
> --Sergio.
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using identifiers before they are defined

2012-06-12 Thread Emile van Sebille

On 6/12/2012 10:53 AM Julio Sergio said...



So I modified my module:

   global something

   a = something(5)


   def something(i):
   return i


And this was the answer I got from the interpreter:

->>>  import tst

Traceback (most recent call last):
   File "", line 1, in
   File "tst.py", line 12, in
 a = something(5)
NameError: global name 'something' is not defined


Do you have any comments?


python executes each line as it encounters it.  a=something(5) as you 
have it attempts to bind the label 'a' to the result of something(5) 
which has not yet been defined.  You seem to want it to compile 
everything first, then execute but it doesn't work that way.


Emile





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


Re: using identifiers before they are defined

2012-06-12 Thread MRAB

On 12/06/2012 18:53, Julio Sergio wrote:

I'm puzzled with the following example, which is intended to be a part of a
module, say "tst.py":

   a = something(5)

   def something(i):
   return i



When I try:

->>>  import tst

The interpreter cries out:

Traceback (most recent call last):
   File "", line 1, in
   File "tst.py", line 11, in
 a = something(5)
NameError: name 'something' is not defined

I know that changing the order of the definitions will work, however there are
situations in which referring to an identifier before it is defined is
necessary, e.g., in crossed recursion.

So I modified my module:

   global something

   a = something(5)


   def something(i):
   return i


And this was the answer I got from the interpreter:

->>>  import tst

Traceback (most recent call last):
   File "", line 1, in
   File "tst.py", line 12, in
 a = something(5)
NameError: global name 'something' is not defined


Do you have any comments?

In Python, "def" is a statement, not a declaration. It binds the body of 
the function

to the name when the "def" statement is run.

A Python script is, basically, run from top to bottom, and both "def"
and "class" are actually statements, not declarations.

A function can refer to another function, even one that hasn't been
defined yet, provided that it has been defined by the time it is called.

For example, this:

def first():
second()

def second():
pass

first()

is OK because it defines function "first", then function "second", then
calls "first". By the time "first" calls "second", "second" has been
defined.
--
http://mail.python.org/mailman/listinfo/python-list


Re: using identifiers before they are defined

2012-06-12 Thread Julio Sergio
Jose H. Martinez  gmail.com> writes:

> 
> 
> You should define the function first and then call it.
> 
> 
>  def something(i):     return i
> 
> 
> a = something(5)
> 
> 
> If you want a reference to the function somewhere else you can do this:
> 

I know that. That was what I meant by "changing the order of the definitions 
will work" in my original message.

And I insist in the issue, which is not trivial... In my message I mentioned 
"crossed recursion", and I delve into it here:

Suppose I have to define two functions, aa, and, bb that are designed to call 
each other:

  def aa():
 ...
 ... a call of bb() somewhere in the body of aa
 ...

  def bb():
 ...
 ... a call of aa() somewhere in the body of bb
 ...


Whatever the order of definition of aa and bb the problem remains, one of the 
two identifiers is not known ...

Most of computer languages have mechanisms to deal with this issue. Is there 
any 
in Python or it is in disadvantage with respect to other languages like C++, 
Java, Perl, PHP, etc.?




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


Re: using identifiers before they are defined

2012-06-12 Thread Jerry Hill
On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio  wrote:
> Suppose I have to define two functions, aa, and, bb that are designed to call
> each other:
>
>  def aa():
>     ...
>     ... a call of bb() somewhere in the body of aa
>     ...
>
>  def bb():
>     ...
>     ... a call of aa() somewhere in the body of bb
>     ...
>
>
> Whatever the order of definition of aa and bb the problem remains, one of the
> two identifiers is not known ...

This works just fine in python, exactly as you've written it.  What's
the actual problem you're having?

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


Re: using identifiers before they are defined

2012-06-12 Thread Evan Driscoll

On 01/-10/-28163 01:59 PM, Julio Sergio wrote:

I know that changing the order of the definitions will work, however there are
situations in which referring to an identifier before it is defined is
necessary, e.g., in crossed recursion.


Mutual recursion isn't a problem: the following strange expression of 
factorial works fine:


def strange_helper(x):
return factorial(x)

def factorial(x):
if x==0:
return 1
else:
return x * strange_helper(x-1)

print factorial(5)


The reason is names are never looked up when the parser sees them, but 
rather only when execution reaches them. So the fact that 'factorial' 
hasn't been defined yet when the parser is dealing with 'strange_helper' 
is fine, because when 'strange_helper' is actually *called*, 'factorial' 
has been defined.


Here's another example to illustrate, in a different manner that doesn't 
use this "undefined" thing:


def foo():
print "Inside the first version of foo"

def call_foo():
foo()

call_foo()

def foo():
print "Inside the second version of foo"

call_foo()

This prints:
 Inside the first version of foo
 Inside the second version of foo


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


Re: using identifiers before they are defined

2012-06-12 Thread Ethan Furman

Julio Sergio wrote:

Jose H. Martinez  gmail.com> writes:



You should define the function first and then call it.


 def something(i): return i


a = something(5)


If you want a reference to the function somewhere else you can do this:



I know that. That was what I meant by "changing the order of the definitions 
will work" in my original message.


And I insist in the issue, which is not trivial... In my message I mentioned 
"crossed recursion", and I delve into it here:


Suppose I have to define two functions, aa, and, bb that are designed to call 
each other:


  def aa():
 ...
 ... a call of bb() somewhere in the body of aa
 ...

  def bb():
 ...
 ... a call of aa() somewhere in the body of bb
 ...


Whatever the order of definition of aa and bb the problem remains


No.  The reply from MRAB explains this.

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


Re: using identifiers before they are defined

2012-06-12 Thread Jose H. Martinez
Seems like what you need is

from othermodule import bb

def aa():
bb()



On Tue, Jun 12, 2012 at 2:51 PM, Ethan Furman  wrote:

> Julio Sergio wrote:
>
>> Jose H. Martinez  gmail.com> writes:
>>
>>
>>> You should define the function first and then call it.
>>>
>>>
>>>  def something(i): return i
>>>
>>>
>>> a = something(5)
>>>
>>>
>>> If you want a reference to the function somewhere else you can do this:
>>>
>>>
>> I know that. That was what I meant by "changing the order of the
>> definitions will work" in my original message.
>>
>> And I insist in the issue, which is not trivial... In my message I
>> mentioned "crossed recursion", and I delve into it here:
>>
>> Suppose I have to define two functions, aa, and, bb that are designed to
>> call each other:
>>
>>  def aa():
>> ...
>> ... a call of bb() somewhere in the body of aa
>> ...
>>
>>  def bb():
>> ...
>> ... a call of aa() somewhere in the body of bb
>> ...
>>
>>
>> Whatever the order of definition of aa and bb the problem remains
>>
>
> No.  The reply from MRAB explains this.
>
> ~Ethan~
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-12 Thread CM
On Jun 11, 6:55 pm, Dietmar Schwertberger 
wrote:

> But then we're back to the initial point: As long as there's no GUI
> builder for Python, most people will stick to Excel / VBA / VB.

Then good thing there *are* GUI builder/IDEs for Python, one of which
was good enough for me to take me from essentially zero modern
programming experience to a sizable (> ~15k LOC) application.
-- 
http://mail.python.org/mailman/listinfo/python-list


Using pdb with greenlet?

2012-06-12 Thread Salman Malik

Hi,

I am sort of a newbie to Python ( have just started to use pdb). 

My problem is that I am debugging an application that uses greenlets and when I 
encounter something in code that spawns the coroutines or wait for an event, I 
lose control over the application (I mean that after that point I can no longer 
do 'n' or 's' on the code). Can anyone of you tell me how to tame greenlet with 
pdb, so that I can see step-by-step as to what event does a coroutine sees and 
how does it respond to it.

Any help would be highly appreciated.

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


Re: which one do you prefer? python with C# or java?

2012-06-12 Thread Tim Johnson
* Tomasz Rola  [120611 11:18]:
> On Sat, 9 Jun 2012, Yesterday Paid wrote:
> 
> > I'm planning to learn one more language with my python.
> > Someone recommended to do Lisp or Clojure, but I don't think it's a
> > good idea(do you?)
> > So, I consider C# with ironpython or Java with Jython.
> > It's a hard choice...I like Visual studio(because my first lang is VB6
> > so I'm familiar with that)
> > but maybe java would be more useful out of windows.
> > 
> > what do you think?
> 
> If you don't know C yet, I second recommendation to learn it. It is a very 
> 70-tish and 80-tish language, but it is still very relevant if you want to 
> call yourself a programmer (rather than a hobbyist, with all credits due 
> to clever genius hobbyists out there). There are things I would rather do 
> in C than in any other language (like, writing a Python interpreter or 
> Linux kernel - wait, what you say they have been written already?). Also, 
> it gives one a way to handtune the code quite a lot (at expense of time, 
> but this is sometimes acceptable), to the point where next choice is 
> assembly (and results not necessarily better)...
> 
> Later on, since C and C++ share quite a bit, you can gradually include C++ 
> elements into your code, thus writing in a kinda "bettered C" (compiled 
> with C++ compiler), using constructs like "const" to make your programs 
> more correct. And you will learn to not use "new" for variables, which is 
> good thing. However, some C++ constructs include performance penalty, so 
> it is good to not better it too much.
  I concur, I worked in C and C++ for 12 years. I added C++ later in
  my programming life. I don't recommend C++ for single programmers.
  - that is to say - 1 coder for 1 codebase. One can do good enough
  OOP in ansi C believe it or not, I learned to.

  It is interesting to note that most of linux is written in C,
  rather than C++ and is not python as well?
 
> - Common Lisp - "nice industrial standard" (depends on one's preferred 
> definition of "nice", of course, as well as "industrial" and "standard")
  I took a hard look at Common Lisp at one time. I got the
  impression that the "Common Lisp" is not to Lisp what Ansi C is to
  C. 
  
  IOWS, there does remain incompatibilities between different
  Common Lisp implementations.

  Whereas Ansi C is pretty strict as code portability (or was so
  when I was working in it)
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using identifiers before they are defined

2012-06-12 Thread Julio Sergio
Ethan Furman  stoneleaf.us> writes:

> 
> 
> No.  The reply from MRAB explains this.
> 
> ~Ethan~
> 

Thanks, you're right!
I was confusing statemens with declarations.





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


Re: using identifiers before they are defined

2012-06-12 Thread Ethan Furman

Julio Sergio wrote:

Ethan Furman  stoneleaf.us> writes:



No.  The reply from MRAB explains this.

~Ethan~



Thanks, you're right!
I was confusing statemens with declarations.


Yeah, it took me a while to get that straight as well.

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


RE: Create directories and modify files with Python

2012-06-12 Thread Prasad, Ramit
> > Thanks for the directions. By the way, can you see my post in Google Groups?
> I'm not able to, and I don't know why.
> >
> They may have copied the Gmail idea that you never need to see anything
> anything you posted yourself.

I can see all my posts in a Gmail thread/conversation but if there are no 
replies then I would have to look in All Mail. But for "normal" email
conversations it does have my posts in there. 

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

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


multiprocessing: excepthook not getting called

2012-06-12 Thread Dave Cook
Why doesn't my excepthook get called in the child process?

import sys
import multiprocessing as mp

def target():
name = mp.current_process().name
def exceptHook(*args):
print 'exceptHook:', name, args
sys.excepthook = exceptHook
raise ValueError

if __name__=='__main__':
p = mp.Process(target=target)
p.start()
p.join()
# try it here in main
target()

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-12 Thread rdsteph
On Jun 10, 12:37 pm, Dietmar Schwertberger 
wrote:
> Personally, I prefer Python with console, wx or Qt for local
> applications and Python/HTTP/HTML/Javascript for multi-user
> database applications.
>
> Regards,
>
> Dietmar

+1

I think this is the wave of the furture for deploying simple programs
to many users. It is almost 100% cross platform (can be used on
desktop, smartphone, tablet, windows, linux, mac etc) and is very easy
to do, even for casual "non-programmers" who do a little programming
(such as many engineers).

I think efforts to make a better, and more definitive, "GUI builder"
for Python should focus on makigng an easy to use "IDE" for creating
these kinds of Python-HTMl-Javascript front ends for applications.

*That* would really help Python's popularity to take off and expode.

Ron Stephens

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


Re: Where to set default data - where received, or where used

2012-06-12 Thread Chris Angelico
On Tue, Jun 12, 2012 at 4:37 AM, Dennis Carachiola  wrote:
> Here's my question.  I could do this by creating the dictionary with
> the default values, then read the file into it.  Or I could use a
> 'get' with default values at the location in the program where those
> values are used.

Both options have their recommendations. As others have said, setting
your defaults in one place has advantages of coherence; but setting
them at point of read keeps all the code using it together. You can
have an entirely dumb I/O submodule that feeds smart other-modules.
Take your pick based on what you're doing.

What I would definitely suggest, though, is making a structured config
file. (You could "cheat" by importing it as a module and making it
simply Python code.) Provide a template config file with lots of
explanatory comments, and (crucially) every config entry given,
commented out, and set to its default.

# Configures the default and maximum flurble percentages
# Flurblization increases from the default until either the maximum is
# reached, or max_sort_memory is exceeded, whichever comes first.
#flurble_default = 10
#flurble_max = 30

Having all your defaults in one place makes it easier to produce this
sort of file; in fact, you could have your documentation there as
well. It does become a little more maintenance work, though. It's
possible to have a hybrid, where you run a preprocessor over your code
that analyzes it, collects all config entries, and builds your config
file parser... but that may be beyond the scope of your project.

Anything you can imagine can be done in code. It's just a question of
how much work. :)

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 07:42:56 -0400, D'Arcy Cain 
wrote:
>I guess I am in the minority then.  I do plan to turn one of my larger
>projects into a standalone web server some day but so far writing
>simple Python CGI scripts has served me fine.  I even do some embedding
>by using server side scripting.

Out of curiosity, why did you choose to write CGI scripts or embedded
server-side scripting while standalone web servers are usually
presented as _the_ solution for Python (Django, Pylons, etc.)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 22:01:10 +1000, Chris Angelico 
wrote:
>Apache's mod_php partially evens out the difference, but not
>completely, and of course, it's perfectly possible to write a dispatch
>loop in PHP, as Octavian said.

It looks like mod_php and equivalents for web servers other than
Apache are anecdotal compared to solutions based on standalone web
servers. Is that the case? Why is that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 20:18:21 +1000, Chris Angelico 
wrote:
>Think of it as Apache + PHP versus Python. Apache keeps running, it's
>only your PHP script that starts and stops. With a long-running
>process, you keep everything all in together, which IMHO is simpler
>and better.

Why is a long-running process better?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 14:28:22 +0300, "Octavian Rasnita"
 wrote:
>Otherwise... if you want you can also create a web app using PHP and 
>CodeIgniter web framework and run it with fastcgi...

Thanks for the infos.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Chris Angelico
On Wed, Jun 13, 2012 at 9:59 AM, Gilles  wrote:
> On Tue, 12 Jun 2012 20:18:21 +1000, Chris Angelico 
> wrote:
>>Think of it as Apache + PHP versus Python. Apache keeps running, it's
>>only your PHP script that starts and stops. With a long-running
>>process, you keep everything all in together, which IMHO is simpler
>>and better.
>
> Why is a long-running process better?

It's far simpler to manage, it retains running state, and is easily
enough encapsulated. It's the non-magic way of doing things. Also, it
plays very nicely with the MUD style of process, which is something I
do a lot with Pike. Plus, if you manage it right, you have a guarantee
that you can never be in a half-updated state - that's somewhat tricky
when you have inter-dependencies in PHP code and the file system
itself manages things. What happens if a request comes in while you're
half-way through uploading new code to the server? By default, you
could use half old code and half new code. Keeping everything in
memory makes it easier to prevent that.

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


Re: using identifiers before they are defined

2012-06-12 Thread Ben Finney
Julio Sergio  writes:

> Suppose I have to define two functions, aa, and, bb that are designed
> to call each other:
>
>   def aa():
>  ...
>  ... a call of bb() somewhere in the body of aa
>  ...
>
>   def bb():
>  ...
>  ... a call of aa() somewhere in the body of bb
>  ...
>
>
> Whatever the order of definition of aa and bb the problem remains, one
> of the two identifiers is not known ...

What problem? Can you show actual code that we can execute, which
demonstrates the problem?

-- 
 \ “I turned to speak to God/About the world's despair; But to |
  `\   make bad matters worse/I found God wasn't there.” —Robert Frost |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which one do you prefer? python with C# or java?

2012-06-12 Thread rusi
On Jun 12, 3:19 am, Matej Cepl  wrote:
> On 11/06/12 06:20, rusi wrote:
>
> > Hi Matěj! If this question is politically incorrect please forgive me.
> > Do you speak only one (natural) language -- English?
> > And if this set is plural is your power of expression identical in
> > each language?
>
> I have written about that later ... no, I am a native Czech, but I have
> passive Russian, and active English. But there is a difference ... I can
> read and enjoy beautiful texts in Russian or English (couple of months
> read Eugen Onegin in Russian and that's just a beauty! or C.S.Lewis ...
> oh my!) but I will never be able to write professionally in these
> languages. I can write (as evidenced by this message) somehow in
> English, but I cannot imagine that I would be ever professional art
> writer or (even worse) poet. I could imagine (if spent couple of
> thousands of days working on it) that I would be a Czech professional
> writer though.
>
> Matěj

If we were back-translate that standard to the programming field it
would go something like:
"You cannot call yourself a programmer until you create something of
significance.
So Linus writing the linux kernel or Knuth writing Tex or Stallman
writing emacs, GvR writing Python are programmers; the rest not."

Believe me your English is good enough and better than some mono-
lingual ranters on this list who cannot write 2 straight correct
sentences yet take it upon themselves to correct others' English.

[Sorry for pontificating. I am nearing 50 and have wasted too much of
my life in the misguided pursuit of perfectionism.  I would wish for
younger folks to not err samely]

To come back to the OP's question, Alan Perlis said:
A language that doesn't affect the way you think about programming, is
not worth knowing.
More gems here: http://en.wikiquote.org/wiki/Alan_Perlis

If you use this to choose what language to learn, you cant go wrong.
Most programmers who know dozens of programming languages really know
only one imperative language iced with different syntax.  Which
reminds me of another quip by Alan Perlis:

Syntactic sugar causes cancer of the semicolon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread D'Arcy Cain

On 12-06-12 07:57 PM, Gilles wrote:

On Tue, 12 Jun 2012 07:42:56 -0400, D'Arcy Cain
wrote:

I guess I am in the minority then.  I do plan to turn one of my larger
projects into a standalone web server some day but so far writing
simple Python CGI scripts has served me fine.  I even do some embedding
by using server side scripting.


Out of curiosity, why did you choose to write CGI scripts or embedded
server-side scripting while standalone web servers are usually
presented as _the_ solution for Python (Django, Pylons, etc.)?


History and laziness I suppose.  My biggest project started out as Tcl
and was switched to Python around 1.5.  Besides, the boys and girls
at Apache have done a great job.  May as well build on that.  Even
if I go with a standalone server I will probably put Apache in front
of it for images, style sheets and other static content.  I also want
to look into writing Apache modules in Python some day.

--
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
--
http://mail.python.org/mailman/listinfo/python-list


Internationalized domain names not working with URLopen

2012-06-12 Thread John Nagle

I'm trying to open

http://пример.испытание

with

urllib2.urlopen(s1)

in Python 2.7 on Windows 7. This produces a Unicode exception:

>>> s1
u'http://\u043f\u0440\u0438\u043c\u0435\u0440.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435'
>>> fd = urllib2.urlopen(s1)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
  File "C:\python27\lib\urllib2.py", line 394, in open
response = self._open(req, data)
  File "C:\python27\lib\urllib2.py", line 412, in _open
'_open', req)
  File "C:\python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
  File "C:\python27\lib\urllib2.py", line 1199, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "C:\python27\lib\urllib2.py", line 1168, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "C:\python27\lib\httplib.py", line 955, in request
self._send_request(method, url, body, headers)
  File "C:\python27\lib\httplib.py", line 988, in _send_request
self.putheader(hdr, value)
  File "C:\python27\lib\httplib.py", line 935, in putheader
hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
0-5: ordinal not in range(128)

>>>

The HTTP library is trying to put the URL in the header as ASCII.  Why 
isn't "urllib2" handling that?


What does "urllib2" want?  Percent escapes?  Punycode?

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


Re: Internationalized domain names not working with URLopen

2012-06-12 Thread Andrew Berg
On 6/13/2012 1:17 AM, John Nagle wrote:
> What does "urllib2" want?  Percent escapes?  Punycode?
Looks like Punycode is the correct answer:
https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode

I haven't tried it, though.
-- 
CPython 3.3.0a3 | Windows NT 6.1.7601.17790


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


Re: Internationalized domain names not working with URLopen

2012-06-12 Thread Виталий Волков
Answer in this topic should help you to solve issue.

http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top


Regards.

2012/6/13 John Nagle 

> I'm trying to open
>
> http://пример.испытание 
>
> with
>
> urllib2.urlopen(s1)
>
> in Python 2.7 on Windows 7. This produces a Unicode exception:
>
> >>> s1
> u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\**
> u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435'
> >>> fd = urllib2.urlopen(s1)
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "C:\python27\lib\urllib2.py", line 126, in urlopen
>return _opener.open(url, data, timeout)
>  File "C:\python27\lib\urllib2.py", line 394, in open
>response = self._open(req, data)
>  File "C:\python27\lib\urllib2.py", line 412, in _open
>'_open', req)
>  File "C:\python27\lib\urllib2.py", line 372, in _call_chain
>result = func(*args)
>  File "C:\python27\lib\urllib2.py", line 1199, in http_open
>return self.do_open(httplib.**HTTPConnection, req)
>  File "C:\python27\lib\urllib2.py", line 1168, in do_open
>h.request(req.get_method(), req.get_selector(), req.data, headers)
>  File "C:\python27\lib\httplib.py", line 955, in request
>self._send_request(method, url, body, headers)
>  File "C:\python27\lib\httplib.py", line 988, in _send_request
>self.putheader(hdr, value)
>  File "C:\python27\lib\httplib.py", line 935, in putheader
>hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5:
> ordinal not in range(128)
> >>>
>
> The HTTP library is trying to put the URL in the header as ASCII.  Why
> isn't "urllib2" handling that?
>
> What does "urllib2" want?  Percent escapes?  Punycode?
>
>John Nagle
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list