Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html

2013-08-27 Thread Alan Gauld

On 27/08/13 03:48, Chris Down wrote:


"Keep the width of the lines in your example to under 62 characters wide."

I don't really see any reason to use less than 79 in 2013.


The reason for preferring shorter lines is to leave room for
the chevrons when the message gets quoted multiple times.

eg

>> I don't really see any reason to use less than 79 in 2013.
> The reason for preferring shorter lines is to leave room for
> the chevrons when the message gets quoted multiple times.
 That's just crazy
>>> Maybe but its the reason given
>> I prefer using different colours the way Outlook does it
> But that needs rich text and I hate rich text

And that's a whole new discussion ;-)


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html

2013-08-27 Thread Chris Down
On 2013-08-27 09:49, Alan Gauld wrote:
> The reason for preferring shorter lines is to leave room for
> the chevrons when the message gets quoted multiple times.

I always reformat quotes with `gq' in vim when I am quoting, I suggest others
do the same.


pgp8Ve33ukc7A.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html

2013-08-27 Thread Steven D'Aprano
On Tue, Aug 27, 2013 at 09:49:46AM +0100, Alan Gauld wrote:

> >> I don't really see any reason to use less than 79 in 2013.
> > The reason for preferring shorter lines is to leave room for
> > the chevrons when the message gets quoted multiple times.
>  That's just crazy
> >>> Maybe but its the reason given
> >> I prefer using different colours the way Outlook does it
> > But that needs rich text and I hate rich text

And it also makes it hard to impossible for the colour blind to tell 
what is quoted how many times.


I wish mail clients would support rich text rather than HTML. There 
actually is a standard for rich text which does not have the 
disadvantages of HTML mail (bloat, security implications, vulnerable to 
malware):

http://tools.ietf.org/html/rfc1896

but of course any form of rich text is vulerable to people with rubbish 
taste screaming in ALL CAPS BOLD ITALIC RED TEXT WITH GREEN UNDERLINED 
SPACES BETWEEN WORDS... 

:-)


Since this is a Python list, I should also mention ReST (ReStructured 
Text), which is the Python standard for generating rich text from plain 
text markup (not to be confused with Markdown, which is another 
competing, but not quite as powerful, standard). ReST has the advantage 
that it is human readable. For example:

This is a header


This paragraph contains *italic* and **bold** text.

- These are bullet points.
- No kidding.
- Told you it was readable.


I wish mail clients would support rich text using ReST or Markdown. The 
mail client could still include a GUI so you choose formatting commands 
rather than have to type markup.


-- 
Steven


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html

2013-08-27 Thread Chris Down
On 2013-08-27 20:11, Steven D'Aprano wrote:
> I wish mail clients would support rich text using ReST or Markdown. The 
> mail client could still include a GUI so you choose formatting commands 
> rather than have to type markup.

Why can't you do this through your mailcap instead of relying on the client to
implement that functionality? Works well enough for me.


pgp9_FRLxhvvo.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python execution timer/proficiency testing

2013-08-27 Thread eryksun
On Tue, Aug 27, 2013 at 2:18 AM, Steven D'Aprano  wrote:
> On Mon, Aug 26, 2013 at 08:20:30PM +0200, Dino Bektešević wrote:
>
>> Warning (from warnings module):
>>   File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line
>> 152
>> warnings.warn(msg, RuntimeWarning)
>> RuntimeWarning: The iteration is not making good progress, as measured by
>> the improvement from the last ten iterations.
>>
>> It doesn't seem to produce any error in my data, but how dangerous is this?
>
> That's just telling you that your code is slow.
>
> I say "your code", but it might be scipy, numpy, or code you wrote
> yourself. Or it might simply be that the task you are trying to do is
> hard, and no matter what you do it will always be slow. I'm afraid that
> it will probably take a numpy/scipy expert to tell you which is the
> case.

The MINPACK routine called by fsolve() failed to converge; it quit
after making little or no progress over 10 consecutive iterations.
Maybe you need a better initial estimate; maybe there's no solution.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python execution timer/proficiency testing

2013-08-27 Thread Oscar Benjamin
On 27 August 2013 11:03, eryksun  wrote:
> On Tue, Aug 27, 2013 at 2:18 AM, Steven D'Aprano  wrote:
>> On Mon, Aug 26, 2013 at 08:20:30PM +0200, Dino Bektešević wrote:
>>
>>> Warning (from warnings module):
>>>   File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line
>>> 152
>>> warnings.warn(msg, RuntimeWarning)
>>> RuntimeWarning: The iteration is not making good progress, as measured by
>>> the improvement from the last ten iterations.
>>>
>>> It doesn't seem to produce any error in my data, but how dangerous is this?
>>
>> That's just telling you that your code is slow.
>>
>> I say "your code", but it might be scipy, numpy, or code you wrote
>> yourself. Or it might simply be that the task you are trying to do is
>> hard, and no matter what you do it will always be slow. I'm afraid that
>> it will probably take a numpy/scipy expert to tell you which is the
>> case.
>
> The MINPACK routine called by fsolve() failed to converge; it quit
> after making little or no progress over 10 consecutive iterations.
> Maybe you need a better initial estimate; maybe there's no solution.

Exactly. Dino, whatever scipy routine you're using is warning you that
it has failed. You should heed this warning since it likely means that
your code is not doing what you want it to do. Without knowing what
you're trying to do and what function you're calling I can't say more
than that.


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] i need help with the following question

2013-08-27 Thread Don Jennings

On Aug 27, 2013, at 3:40 AM, isaac Eric wrote:



> print "For a circle of radius %s the area is %s" % (radius,area)

> Question: What is the purpose of %s ?

Okay, so you're just getting started with python. We're happy to do some 
hand-holding, but we encourage you to think first.

You've followed the rest of the instructions and run the program? Don't worry 
about being precise with your answer to this question. Just try to express what 
you think is happening (we'll build on what you give us to make it clearer).

Take care,
Don

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] spss.BasePivotTable

2013-08-27 Thread Albert-Jan Roskam
Ooops, sorry wrong mailing list! ;-)


Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~ 


- Original Message -
> From: Albert-Jan Roskam 
> To: Python Mailing List 
> Cc: 
> Sent: Tuesday, August 27, 2013 3:14 PM
> Subject: [Tutor] spss.BasePivotTable
> 
> Hello,
>  
> I am trying to create a BasePivot table with three columns: one for the 
> labels, 
> one for a a category "Before" and one for "After". The 
> following attempt fails, but what am I doing wrong?
>  
> begin program.
> import spss
> try:
>     spss.StartSPSS()
>     #spss.Submit("get file='demo.sav'.")
>     spss.StartProcedure("proc")
>     table = spss.BasePivotTable("table","mytable")
>     table.Append(spss.Dimension.Place.row,"rowdim")
>     table.Append(spss.Dimension.Place.column,"coldim1")
>     table.Append(spss.Dimension.Place.column,"coldim2")
>     value1 = spss.CellText.Number(23,spss.FormatSpec.Count)
>     value2 = spss.CellText.Number(24,spss.FormatSpec.Count)
>     table[(spss.CellText.String("M"),)] = (value1, value2)
>     spss.EndProcedure()
>     spss.StopSPSS()
> except spss.SpssError:
>     print "Error."
> print spss.GetLastErrorMessage()
> end program.
>  
> Thank you in advance!
> 
> Regards,
> Albert-Jan
> 
> 
> ~~
> All right, but apart from the sanitation, the medicine, education, wine, 
> public 
> order, irrigation, roads, a 
> fresh water system, and public health, what have the Romans ever done for us?
> ~~ 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] spss.BasePivotTable

2013-08-27 Thread Albert-Jan Roskam
Hello,
 
I am trying to create a BasePivot table with three columns: one for the labels, 
one for a a category "Before" and one for "After". The following attempt fails, 
but what am I doing wrong?
 
begin program.
import spss
try:
    spss.StartSPSS()
    #spss.Submit("get file='demo.sav'.")
    spss.StartProcedure("proc")
    table = spss.BasePivotTable("table","mytable")
    table.Append(spss.Dimension.Place.row,"rowdim")
    table.Append(spss.Dimension.Place.column,"coldim1")
    table.Append(spss.Dimension.Place.column,"coldim2")
    value1 = spss.CellText.Number(23,spss.FormatSpec.Count)
    value2 = spss.CellText.Number(24,spss.FormatSpec.Count)
    table[(spss.CellText.String("M"),)] = (value1, value2)
    spss.EndProcedure()
    spss.StopSPSS()
except spss.SpssError:
    print "Error."
print spss.GetLastErrorMessage()
end program.
 
Thank you in advance!

Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~ 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Global var not defined?

2013-08-27 Thread leam hall
Could use some help with this. Python 2.4.3 on RHEL 5.x.

In the functions file that gets imported:

def append_customer(line_list):
global customers
cust = line_list[0] // list with Customer info in [0]
cust = clean_word(cust)  // Trims white space

if len(cust) and cust not in customers:
host_list[cust] = {}
customers.append(cust)


In the calling file:

import functions
import sys

customers = []

.
.
.
for line in input_file:
line = line.strip()
if not len(line):
continue
line_list = line.split(',')
functions.append_customer(line_list)


Error message:
Traceback (most recent call last):
  File "./host_tools.py", line 55, in ?
functions.append_customer(line_list)
  File "/home/lhall/lang/functions.py", line 27, in append_customer
if len(cust) and cust not in customers:
NameError: global name 'customers' is not defined



-- 
Mind on a Mission 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global var not defined?

2013-08-27 Thread Alan Gauld

On 27/08/13 18:58, leam hall wrote:


def append_customer(line_list):
 global customers
 cust = line_list[0] // list with Customer info in [0]
 cust = clean_word(cust)  // Trims white space

 if len(cust) and cust not in customers:
 host_list[cust] = {}
 customers.append(cust)


In Python global only applies to the local file.
Thus customers needs to be at the global level in
functions.py.

But since its a bad use of globals it would be better to just get the 
function to return the value and do the append in the top level file...


BTW the line

>  host_list[cust] = {}

Makes no sense since you are  adding an empty dictionary  to a variable 
that doesn't exist so you should get an error. I assume you have 
simplified the code somewhat?



In the calling file:

import functions
import sys

customers = []
.
.
for line in input_file:
 line = line.strip()
 if not len(line):
 continue
 line_list = line.split(',')
 functions.append_customer(line_list)


   customers.append(functions.get_customer(line_list, customers))

Avoids any need for globals.

Personally I'd move the line split into the function so your loop looks 
like:


for line in input_file:
 line = line.strip()
 if line:
customers.append(functions.get_customer(line_list, customers))

Alternatively I'd put the customers list into a module called customer
and move the customer functions into that module. And then it looks
like I might have a Customer class emerging... And maybe the code above 
would become a class method:

   Customer.readFromFile(aFile) -> [cust1, cust2, ...]


Just a thought...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global var not defined?

2013-08-27 Thread Prasad, Ramit
leam hall wrote:
> Could use some help with this. Python 2.4.3 on RHEL 5.x.
> 
> In the functions file that gets imported:
> 
> def append_customer(line_list):
>     global customers
>     cust = line_list[0] // list with Customer info in [0]
>     cust = clean_word(cust)  // Trims white space
> 
>     if len(cust) and cust not in customers:
>     host_list[cust] = {}
>     customers.append(cust)
> 
> In the calling file:
> 
> 
> import functions
> import sys
> 
> customers = []
> 
> .
> .
> .
> for line in input_file:
>     line = line.strip()
>     if not len(line):
>     continue
>     line_list = line.split(',')
>     functions.append_customer(line_list)
> 
> Error message:
> Traceback (most recent call last):
>   File "./host_tools.py", line 55, in ?
>     functions.append_customer(line_list)
>   File "/home/lhall/lang/functions.py", line 27, in append_customer
>     if len(cust) and cust not in customers:
> NameError: global name 'customers' is not defined
> 
> 

The problem is because "customers" needs to be defined
in the module with the append_customers. Global as
written refers to module level variables.

Some (possible and untested) methods to get around this are: 
1. pass in customers as an argument 
2. use globals()? 
3. add it to functions module `functions.customers = customers`.


~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.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global var not defined?

2013-08-27 Thread leam hall
Well, I'm happy to change things but my python is only so good. And much of
that is based off of shell programming.

What the data looks like is fairly simple. I have a spreadsheet of host
information. Customer 'Alan' may have a dozen or so servers and customer
Ramit has another dozen or two. When I print these out they will be sorted
by customer but rolled into a single file.

The line "host_list[cust] = {}" creates the customer dictionary if that
customer doesn't exist. Then there's a host key with multiple layers:

   host_list['alan']['webserver']['ip'] = '12.23.34.45'
   host_list['alan']['webserver']['environ'] = 'Dev'

Make sense? As I do not know a lot about classes I'm not sure they are
better in this case than a multi-level dictionary. The data does not get
altered, just organized.

Leam


On Tue, Aug 27, 2013 at 2:34 PM, Prasad, Ramit wrote:

> leam hall wrote:
> > Could use some help with this. Python 2.4.3 on RHEL 5.x.
> >
> > In the functions file that gets imported:
> >
> > def append_customer(line_list):
> > global customers
> > cust = line_list[0] // list with Customer info in [0]
> > cust = clean_word(cust)  // Trims white space
> >
> > if len(cust) and cust not in customers:
> > host_list[cust] = {}
> > customers.append(cust)
> >
> > In the calling file:
> >
> >
> > import functions
> > import sys
> >
> > customers = []
> >
> > .
> > .
> > .
> > for line in input_file:
> > line = line.strip()
> > if not len(line):
> > continue
> > line_list = line.split(',')
> > functions.append_customer(line_list)
> >
> > Error message:
> > Traceback (most recent call last):
> >   File "./host_tools.py", line 55, in ?
> > functions.append_customer(line_list)
> >   File "/home/lhall/lang/functions.py", line 27, in append_customer
> > if len(cust) and cust not in customers:
> > NameError: global name 'customers' is not defined
> >
> >
>
> The problem is because "customers" needs to be defined
> in the module with the append_customers. Global as
> written refers to module level variables.
>
> Some (possible and untested) methods to get around this are:
> 1. pass in customers as an argument
> 2. use globals()?
> 3. add it to functions module `functions.customers = customers`.
>
>
> ~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.
>



-- 
Mind on a Mission 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global var not defined?

2013-08-27 Thread Alan Gauld

On 27/08/13 19:50, leam hall wrote:

Well, I'm happy to change things but my python is only so good. And much
of that is based off of shell programming.



You will need to change something because what you have won;t work.

The question is what to change?


What the data looks like is fairly simple. I have a spreadsheet of host
information. Customer 'Alan' may have a dozen or so servers and customer
Ramit has another dozen or two.


So abstracting that you have several customer objects each containing
a list(or dict?) of servers. Servers in turn have numerous attributes:
name, role, ip, environ etc...


When I print these out they will be
sorted by customer but rolled into a single file.


So the customer objects have a method that prints to a file.

That's the OOP approach, but you can do it without classes
if you want, its just a bit more effort on the readability
and coding front.


The line "host_list[cust] = {}" creates the customer dictionary if that
customer doesn't exist.


It may be better to look at the get() method of dictionaries for that.
But the problem I highlighted was that the top level host_list 
dictionary  didn't exist in your code. You need to initialize

it before you can access the cust key.

host_list = {}
.
.
.
host_list.get(cust, {})


Then there's a host key with multiple layers:

host_list['alan']['webserver']['ip'] = '12.23.34.45'
host_list['alan']['webserver']['environ'] = 'Dev'

Make sense? As I do not know a lot about classes I'm not sure they are
better in this case than a multi-level dictionary.


A class is effectively a dictionary inside so its very similar.
Using my OOP suggestion above this would translate to something like:

alan.servers['webserver'].ip = '12.23.34.45

Which you find more readable is a matter of taste!
There are some other advantages to the OOP approach but
they are not critical here.


The data does not get altered, just organized.


That doesn't make much difference in this case.

The simplest solution to get it working is probably just
to move the customers list into the functions module.
In the longer term the other options might prove more beneficial.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python execution timer/proficiency testing (Dino Bektešević)

2013-08-27 Thread Dino Bektešević
Hello,

First off thank you for the good responses. That's most likely why I
couldn't find it with google, English is not my native language so the
little difference between proficiency and efficiency escaped me.
I apologize for HTML text first time I sent something from gmail there
seemed to be no issues.

2013/8/27  :
> Message: 5
> Date: Tue, 27 Aug 2013 00:04:19 + (UTC)
> From: Dave Angel 
> To: tutor@python.org
> Subject: Re: [Tutor] Python execution timer/proficiency testing
> Message-ID: 
> Content-Type: text/plain; charset=ISO-8859-2
>
>> I don't dare to run my program on a batch of ~9.5million images 
>> because I can't assert how long could it last and because of obvious 
>> space issues my program edits the information on
>>  the images and then overwrites the original data. Should something go
>> awry I'd have to spend a long time cleaning it up.
>
> Doesn't matter how slow or fast a program is.  If it's not reliable,
> you'd better not run it with in-place updating of valuable data.  And if
> it is reliable, so you trust it, but too slow to run in one pass, then
> you'd better arrange that each file is recognizably done or not done.
> For example, you might drop a marker into a directory, make a copy of
> that directory, work on the copy, then only when the whole directory is
> finished do you move the files back where they belong and remove the
> marker.  Pick your method such that it would only take a few seconds for
> the program to figure out where it had left off.
>
>> My plan is to test average profficiency on ~100 000 images to see how
>> it fairs and what to do next.
>> So far it takes about 1.5-2sec per image using the 
>> "guess_by_eye" method (which isn't long,
>
> If we assume 1 second per file, you're talking 3 years of execution
> time for 10 million files.  Assuming you can wait that long, you'll also
> have to figure that the program/os/computer will crash a few times in
> that span.  So restartability is mandatory.  is anything else going to
> be using these files, or this computer, in the meantime?
>
> How big are these files, in total?  It may be much more practical to
> have a separate drive(s) to hold the results.
>

The entire database is ~60TB large so you don't have to worry that I
will try to run the entire thing at once on one computer. They will be
split up in smaller sections called 'runs' couple of runs will be
processed on a single comp and multiple comps will be used. Number of
files per run varies and I will most likely not try to change that.
The computers will not be used for anything else in the meantime. I'm
still waiting to hear from my mentor if the server will be available.
They are 'FITS' files and also vary from 12-16MB taken from Sloan
Digital Sky Survey (SDSS) db. Because of the organisation of FITS
files I need the information in 'headers' to further process the image
itself, by overwriting the original data I save space and time it
takes me to copy paste the files. However you are right I will mostly
likely add a 'FLAG' entry into the header so I can restart should
something happen.


> Date: Tue, 27 Aug 2013 00:04:19 + (UTC)
> From: eryksun 
> To: tutor@python.org, Dino Bektešević 
> Subject: Re: [Tutor] Python execution timer/proficiency testing
>The MINPACK routine called by fsolve() failed to converge; it quit
>after making little or no progress over 10 consecutive iterations.
>Maybe you need a better initial estimate; maybe there's no solution.


> From: Oscar Benjamin 
> To: tutor@python.org, Dino Bektešević , eryksun 
> 
> Subject: Re: [Tutor] Python execution timer/proficiency testing
>Exactly. Dino, whatever scipy routine you're using is warning you that
>it has failed. You should heed this warning since it likely means that
>your code is not doing what you want it to do. Without knowing what
>you're trying to do and what function you're calling I can't say more
>than that.


Thank you both I did not know it quits(!) but since my further code
never reported an error I assume it returned something similar to
initial guess?
I will add a test of the returned variable ier and try to find another
initial guess or handle it somehow else.
Under 'Narrow-field astrometry' are the equations I'm solving and
here's the code snippet:


row_guess = ( mudiff*fd['f'] - fd['c']*nudiff )/det
col_guess = ( fd['b']*nudiff - mudiff*fd['e'] )/det

row=zeros(mu.size,dtype='f8')
col=zeros(mu.size,dtype='f8')
for i in xrange(mu.size):
self._tmp_color=color[i]

self._tmp_munu=array([mu[i],nu[i]])

rowcol_guess=array([row_guess[i], col_guess[i]])

rowcol = scipy.optimize.fsolve(self._pix2munu_for_fit, rowcol_guess)
row[i] = rowcol[0]
col[i] = rowcol[1]


Thanks,
Dino
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.system() not working

2013-08-27 Thread Nitish Kunder
Hii
I have a python program which i am calling from a php script.
The arguments to the program is a path to the file
The program when directly run from console executes normally.
But when I try to execute the program from browser ie call the python
script from php,
os.system command is not working what might be the problem.
Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html

2013-08-27 Thread Rick Moen
/me waves to esteemed tutors and helpers.


Quoting Bob Gailer (bgai...@gmail.com):

> I have a reaction to 
> http://www.catb.org/esr/faqs/smart-questions.html and I'd like your 
> feedback. Perhaps I will then send revised comments to the authors of 
> the [essay].

As one of the essays' co-authors, I'm always interested in thoughts,
especially ones about how to improve the fool thing.  (As you'll see
below , I have more than a few, myself.)

> I found myself a bit disappointed. 

Me too.  (No irony intended.)  Eric and I never quite achieved what we
hoped with it.

> All I see at first is email links and Revision History. If I did not 
> know to scroll down I might have just figured I was at the wrong page.
> 
> Reading translations and disclaimer is not why I'd come here.

Personally, I'd have tried to put the links to translations and the
revision history at the end, if possible.  Eric maintains the master
version, and IIRC uses a Docbook XML toolkit with a precooked
stylesheet.  I've never personally tried to significantly hack such
tools to customise presentation.  As maintainer of one Linuxdoc
SGML-format FAQ and one Docbook SGML-format HOWTO for the Linux
Documentation Project, I've long been a bit dissatisfied with the
somewhat inflexible document structure the related toolkits push authors
towards.  Perhaps Eric found likewise; I'd have to ask him.

Anyway, my point is that as an author, I'd generally rather spend time
writing than hacking madly on document-production tools to rearrange the
elements and alter the presentation.  Time permitting, I do hope to get
around to working with Eric to see if the order of elements can be
rearranged with reasonable ease.  However, there are much larger
problems, which I'll get to in a minute.

> With contact names and email at the bottom

Objecting to e-mail links' living at the top doesn't seem
reasonable, sorry.  Those are merely the names of us co-authors.
If it really bothers you to see authors' names at the top of what they
write, Bob, you might want to quit the habit of reading before you
become truly vexed, as you'll see it more often than not.  Books in
particular are going to be a huge disappointment to you.

As to the 'disclaimer', can you guess _why_ it is there?  

Let me tell you, sir:  For over a decade, every single day of every
single year, I get at least a half dozen misdirected helpdesk requests
in my personal e-mail.  Most are for technical projects (mostly
software, but not always) I've never even heard of.  Often, they are
demanding and downright rude in their insistance that I help the querent
with $FOO for some bizarre value of FOO _right now_.  I'm always nice to
them and try to send them in the right direction, but _man_

The 'disclaimer', the bit that says that Rick and Eric are not a
helpdesk for several thousand projects they (mostly) haven't even heard
of, and please for gosh sakes avoid pegging the irony metre and
send your help requests to the right place, has cut the daily inflow.
I used to get several dozen per day.

I'm sorry you're annoyed by seeing it, but not moved to think it's a bad
idea.  Rather the contrary.  If anything, I'm pondering the virtues of
 tags and red text, man.[1]


> There's a lot of words to wade thru 

Exactly.  That is the biggest problem, and it's fundamental such that it
can be addressed properly only through a do-over.


Let me recount what happened.  Around 2000, Eric and I became aware that
we were more-or-less writing the same sort of essay (except Eric's
wording is pitched as advice to those seeking technical help from
'hackers', while I just was generically talking about online technical
help).  We joined forces, with Eric keeping the master copy and using
his document-production toolchain.

We put out a nice -little-, tightly focussed essay.  To our
astonishment, it proved very popular.  Thousands (at minimum) of
technical projects linked to it from their help pages.

Correspondents kept asking us to add things:  'You should also cover
$FOO.' We're obliging people and tried to accomodate most such requests.
And they kept coming.  Lather, rinse, repeat.  Over ten years later, we
now realise to our dismay:  no more nice -little-, tightly focussed
essay.

What can I say?  We tried, we wrote, people asked us to add more, we
obliged, and the results have gradually become bloated.  (Tolkien said
'It grew in the telling.'   Ours did, too, albeit there the comparison
ends.)

Moreover, it's an unsatisfyingly linear piece, which is not really what
is needed.  _That_ along with sheer bloat makes it, IMO, fail at its
original goal of helping frustrated and impatient people deal better
with techincal projects' online help forums.

So, I've been wanting to sit down and start over from scratch, and this
time write a nice -little-, tightly focussed essay using a radically
different format of some drill-down-for-more variety.  Some toolkit
hacking may be required -- or maybe just roll my own, in Python,

Re: [Tutor] Global var not defined?

2013-08-27 Thread Steven D'Aprano

On 28/08/13 03:58, leam hall wrote:

Could use some help with this. Python 2.4.3 on RHEL 5.x.

In the functions file that gets imported:

def append_customer(line_list):
 global customers


Globals are not "globally global", they are global to the module. Otherwise 
variables defined in module X would stomp all over variables defined in module Y, 
unpredictably depending on the order than modules were imported.



In the calling file:

import functions
import sys

customers = []



This cannot work, because it belongs to a different namespace (module). Just pass 
customers as an explicit parameter to append_customer, and then google for "Global 
variables considered harmful".

If you absolutely must emulate COBOL programmers of the 1970s and insist on 
using globals, write:

functions.customers = []

instead.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.system() not working

2013-08-27 Thread Alan Gauld

On 27/08/13 11:33, Nitish Kunder wrote:

I have a python program which i am calling from a php script.


How are you executing the PHP script?
Which OS? Which web server? Which browser?
Have you tried others?


The arguments to the program is a path to the file
The program when directly run from console executes normally.


So the script itself is fine.


But when I try to execute the program from browser ie call the python
script from php,
os.system command is not working what might be the problem.


It may be that the browser is not allowed to execute system commands (I 
hope not since that would be a huge security issue!) But I suspect you 
are actually running this from a webserver not a browser - that's the 
usual PHP environment. The webserver runs PHP which renders up HTML out 
to the browser. In that case the os.system call will try to run on the 
web server. But it will be running under the webserver account which, 
again for good reason, may not be permitted to execute system commands.


Other than that its hard to say anything since you don't tell us what 
os.system() is trying to execute nor what "not working" means.


Finally remember that os.system() does not give you any access to data 
output by the command, you only get the exit code returned. You will 
need to use the subprocess module if you want to use the output of the 
system command (eg to send it to the browser to display).


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python execution timer/proficiency testing (Dino Bektešević)

2013-08-27 Thread Oscar Benjamin
On 27 August 2013 15:05, Dino Bektešević  wrote:
> Thank you both I did not know it quits(!) but since my further code
> never reported an error I assume it returned something similar to
> initial guess?
> I will add a test of the returned variable ier and try to find another
> initial guess or handle it somehow else.
> Under 'Narrow-field astrometry' are the equations I'm solving and
> here's the code snippet:
>
>
> row_guess = ( mudiff*fd['f'] - fd['c']*nudiff )/det
> col_guess = ( fd['b']*nudiff - mudiff*fd['e'] )/det
>
> row=zeros(mu.size,dtype='f8')
> col=zeros(mu.size,dtype='f8')
> for i in xrange(mu.size):
> self._tmp_color=color[i]
>
> self._tmp_munu=array([mu[i],nu[i]])
>
> rowcol_guess=array([row_guess[i], col_guess[i]])
>
> rowcol = scipy.optimize.fsolve(self._pix2munu_for_fit, rowcol_guess)

Eryksun guessed that fsolve was the source of the message. If the line
above emits the warning you mentioned then the output most likely is
not a solution to the equations. As Eryksun said it could be that your
initial guess isn't good or it could be that there is no solution.
Another possibility is that you're just not working with a very
well-behaved function: there are solutions but the solver wouldn't
find them no matter how good your initial guess. In any case while it
continues to emit that warning message you cannot trust the results it
returns.

Try passing full_output=True to get more information e.g.:

x, infodict, ier, msg = scipy.optimize.fsolve(..., full_output=True)

Then have a look at the infodict, ier and msg variables to see if they
tell you more about what happened:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] spss.BasePivotTable

2013-08-27 Thread Steven D'Aprano

On 27/08/13 23:14, Albert-Jan Roskam wrote:

Hello,

I am trying to create a BasePivot table with three columns: one for the labels, one for a a 
category "Before" and one for "After". The following attempt fails, but what am 
I doing wrong?


At least two things. Here is the first:


try:

[much code]

except spss.SpssError:
 print "Error."


You should replace that line with:

print """Python gives you a nice traceback showing you exactly
what went wrong and where it went wrong, but I'm not going to
show it to you. Instead, you have to guess, because Screw You.
"""

It's a little more wordy, but more accurate.



And the second:


print spss.GetLastErrorMessage()


You're apparently not reading what the last error message is, or if you have 
read it, you're keeping it a secret from us.


What you actually ought to do is preferably get rid of the try...except 
altogether, at least while debugging. Your aim as a programmer is not to hide 
errors, but to eliminate them. Hiding them only makes it harder to identify the 
errors, which is the first step in eliminating them.

If you truly cannot get rid of the try...except, then do this instead:


try:
[much code]
except spss.SpssError:
print spss.GetLastErrorMessage()
raise



which will give you both the spss last error message, and the Python traceback.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Runestone Python Course

2013-08-27 Thread ram sagar
I am a beginner in python i found the Runestone python learning environment
the best one i came across. CodeLens is the best feature , as it shows the
actual working of the program in graphical way that one will never forget
those details.

Thanks to all the people who involved in this project.

Ram Sagar Mourya


On Sat, Aug 24, 2013 at 12:32 AM, Jim Mooney wrote:

> But I discovered that if you delete the single leading blank in front of
> each line, then it works.
> Maybe their parser doesn't like unindented lines starting with a space...
> =
> That's odd. I haven't had any  of those problems. I wonder if it's your
> browser. I'm using FF. Are you doing the first course or the more advanced
> one? I'm only looking at the first one. If you write them I 've found them
> to be very cooperative, which is the norm for open source stuff if you're
> polite. imagine trying to get through the Microsoft phalanx to the
> programmer, if you could even find them, and then they'd say they had no
> authority to make a change until it was reviewed by the Committee of 400, a
> year from now ;')
>
> Jim
>
>
> On 23 August 2013 01:18, Francesco Loffredo  wrote:
>
>> Omar Abou Mrad wrote:
>>
>>>
>>>
>>>
>>> On Wed, Aug 21, 2013 at 7:52 AM, Jim Mooney 
>>> >> cybervigilante@gmail.**com >> wrote:
>>>
>>> http://interactivepython.org
>>>
>>> 
>>>
>>>
>>> Would be nice if it worked though, logged in through my google account,
>>> now i get this error which I can do nothing about:
>>>
>>>
>>>   Sorry, Something went wrong
>>>
>>> The error is: |invalid request|
>>>
>>>  |It was the same for me|. It gives this error message as soon as I try
>> to run one of their "ActiveCode" examples.
>> But I discovered that if you delete the single leading blank in front of
>> each line, then it works.
>> Maybe their parser doesn't like unindented lines starting with a space...
>>
>> It's a nuisance, though.
>>
>> Francesco
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
>
>
>
> --
> Jim
>
> More and more, science is showing that animals, even "simple" ones, have
> awareness and feelings. There is no hard divide, as the rape-the-earth
> crowd would have us believe..
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.system() not working

2013-08-27 Thread Chris Down
Hello,

On 2013-08-27 16:03, Nitish Kunder wrote:
> I have a python program which i am calling from a php script.
> The arguments to the program is a path to the file
> The program when directly run from console executes normally.
> But when I try to execute the program from browser ie call the python
> script from php,
> os.system command is not working what might be the problem.

Your question is lacking some context, like Alan already mentioned, but my
first suspicions would be:

- Relying on a PATH that doesn't exist/is not as you expect in that environment
- Relying on a working directory that turns out to not be what you expected


pgpYrKxQgRu70.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.system() not working

2013-08-27 Thread Dominik George
Hi,

in any case and apart from what was already said, your setup sounds very 
awkward, if not insane.

Are you sure your implementation is a good idea?

-nik



Nitish Kunder  schrieb:
>Hii
>I have a python program which i am calling from a php script.
>The arguments to the program is a path to the file
>The program when directly run from console executes normally.
>But when I try to execute the program from browser ie call the python
>script from php,
>os.system command is not working what might be the problem.
>Thanks
>
>
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor