Re: What minimum should a person know before saying "I know Python"

2013-09-22 Thread Gene Heskett
On Sunday 22 September 2013 23:41:10 Dennis Lee Bieber did opine:

> On Sun, 22 Sep 2013 14:55:24 -0400, Gene Heskett 
> 
> declaimed the following:
> >Then it seems to me that work in the direction should be an active
> >feature request.  Unforch, as I've said before, I'm rowing this barge
> >with a toothpick for an oar. :)
> >
> >I would be interesting to see if the "bait" is taken. :)
> 
>   Unfortunately, I see that as a requiring a change at the OS level.

Without knowing exactly how this was done on the Miggies, and the level of 
security we have here compared to zero on the amiga because of its flat, no 
mmu memory mapping, precludes my having a thought to argue about it in my 
wildest dreams.

Re ARexx, its biggest Achilles heel was the Rexx.lib, which became so 
obvious that Joanne Dow and someone else whose name I've spaced in the 
ensuing 15 years, actually dissed it, found several buglets and one real 
whoodoozy and fixed them, which enhanced the amiga's long term stability 
such that even the web server only had to be rebooted at 2 to 3 week 
intervals.  Yes, that Joanne Dow, you might remember the name from her bix 
days, is a friend of mine.  Quite a Lady IMO.  About as creative as anyone 
I've ever met in coming up with lady-like versions of screw you etc. ;-)  
Last I knew a year back up the log, she was still working, I don't have too 
many years on her, and my use by date has passed a long time ago Dennis, 
I'll be 79 on the next 4th.

>   Even on the OS that REXX was developed upon, my books give a strong
> hint that the only application that was readily "address app" compatible
> was a text editor. ARexx piggy-backed on the underlying linked list
> messages on "findable" message ports.
> 
>   Until the OS supports a multiple writer IPC with return addressing 
in
> an easy API, it's unlikely to be created. UDP/IP might be a way -- but
> UDP has that nasty unreliability factor. Amiga message ports had
> guaranteed delivery (as long as the receiving process read the queued
> messages; and VMS mailboxes were similar).
> 
>   Multiple writer -- as any process could send messages to the single
> receiving port; it wasn't a socket server style where connection
> requests on a single port would be assigned a distinct port subsequent
> usage.
> 
>   Then again, the Amiga auto-config for boards pre-dates the PCI-
express
> configuration system, which is very similar.

And that, despite being mostly written in Lisp, worked very well.  The fact 
that for every board initialized at boot time required a soft reboot that 
the user wasn't made obviously aware of, could get interesting though.

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)

He only knew his iron spine held up the sky -- he didn't realize his brain
had fallen to the ground.
-- The Book of Serenity
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python, pythontex and plots

2013-09-22 Thread rusi
Take a look at babel
http://www.cs.unm.edu/~eschulte/data/CISE-13-3-SciProg.pdf
http://orgmode.org/worg/org-contrib/babel/intro.html

Its my impression that babel supports everything and more that pylatex does

...the catch is that its under emacs...!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2013-09-22 Thread elisha . java
On Tuesday, October 30, 2007 12:24:04 PM UTC-7, Tim Chase wrote:
> > I have used Python for a couple of projects last year and
>  > I found it extremely useful. I could write two middle size
>  > projects in 2-3 months (part time). Right now I am a bit
>  > rusty and trying to catch up again with Python.
>  >
>  > I am now appearing for Job Interviews these days and I am
>  > wondering if anybody of you appeared for a Python
>  > Interview. Can you please share the questions you were
>  > asked. That will be great help to me.
> 
> While I haven't interviewed precisely for Python, I've been
> on the other (interviewing) end and can offer a few of the
> sorts of things I ask.  I don't expect perfect answers to
> all of them, but they show me a range of what the
> interviewee knows.  I try and give a scattershot of
> questions from the following areas to try and narrow down
> where they fall in terms of pythonability, and then grill
> more deeply around the edges that I find.
> 
> Basic Python:
> =
> - do they know a tuple/list/dict when they see it?
> 
> - when to use list vs. tuple vs. dict. vs. set
> 
> - can they use list comprehensions (and know when not to
>abuse them? :)
> 
> - can they use tuple unpacking for assignment?
> 
> - string building...do they use "+=" or do they build a list
>and use .join() to recombine them efficiently
> 
> - truth-value testing questions and observations (do they
>write "if x == True" or do they just write "if x")
> 
> - basic file-processing (iterating over a file's lines)
> 
> - basic understanding of exception handling
> 
> Broader Basic Python:
> =
> - questions about the standard library ("do you know if
>there's a standard library for doing X?", or "in which
>library would you find [common functionality Y]?")  Most
>of these are related to the more common libraries such as
>os/os.path/sys/re/itertools
> 
> - questions about iterators/generators
> 
> - questions about map/reduce/sum/etc family of functions
> 
> - questions about "special" methods ()
> 
> More Advanced Python:
> =
> - can they manipulate functions as first-class objects
>(Python makes it easy, but do they know how)
> 
> - more detailed questions about the std. libraries (such as
>datetime/email/csv/zipfile/networking/optparse/unittest)
> 
> - questions about testing (unittests/doctests)
> 
> - questions about docstrings vs. comments, and the "Why" of
>them
> 
> - more detailed questions about regular expressions
> 
> - questions about mutability
> 
> - keyword/list parameters and unpacked kwd args
> 
> - questions about popular 3rd-party toolkits (BeautifulSoup,
>pyparsing...mostly if they know about them and when to use
>them, not so much about implementation details)
> 
> - questions about monkey-patching
> 
> - questions about PDB
> 
> - questions about properties vs. getters/setters
> 
> - questions about classmethods
> 
> - questions about scope/name-resolution
> 
> - use of lambda
> 
> Python History:
> ===
> - decorators added in which version?
> 
> - "batteries included" SQL-capible DB in which version?
> 
> - the difference between "class Foo" and "class Foo(object)"
> 
> - questions from "import this" about pythonic code
> 
> Python Resources:
> =
> - what do they know about various Python web frameworks
>(knowing a few names is usually good enough, though
>knowledge about the frameworks is a nice plus) such as
>Django, TurboGears, Zope, etc.
> 
> - what do they know about various Python GUI frameworks and
>the pros/cons of them (tkinter, wx, pykde, etc)
> 
> - where do they go with Python related questions (c.l.p,
>google, google-groups, etc)
> 
> Other Process-releated things:
> ==
> - do they use revision control
>(RCS/CVS/Subversion/Mercurial/Git...anything but VSS) and
>know how to use it well
> 
> - do they write automated tests for their code
> 
> Touchy-feely things:
> 
> - tabs vs. spaces, and their reasoning
> 
> - reason for choosing Python
> 
> - choice of editor/IDE
> 
> Good luck with your interviewing and hope this helped,
> 
> -tkc

I appreciate all these. I thought I knew Python!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python, pythontex and plots

2013-09-22 Thread Steven D'Aprano
chitturk, you will probably get better answers if you actually explain 
your question rather than writing as if we can read your mind. More 
comments below:

On Sun, 22 Sep 2013 19:16:35 -0700, chitturk wrote:

> 1) The file is LaTeX
> 2) the % means LaTeX will ignore it.

Shouldn't you ask this on a LaTeX forum then? How is your problem related 
to Python? If it is a Python error, you should explain how you know it is 
a Python error rather than a LaTeX error, because to me it looks like a 
LaTeX error.


> 3) The question was about using pythontex with LaTeX 

And pythontex is what? An interface to Python via LaTeX? Are you getting 
a Python error or a LaTeX error? It seems to me that you are getting a 
LaTeX error, and that Python is irrelevant here. If you have information 
that suggests otherwise, you should share it with us.


4) I included the file so you (OK, others) could see what I was trying 

Problem is that it is not clear what parts are the file and what parts, 
if any, are your commentary on the file. You shouldn't assume that Python 
programmers will be experts on LaTeX syntax and be able to read your code.


> 5) The problem had to do with accessing a file name within the python
>script using \py{outputfile}

If I am reading your file/comments correctly, the error you get is not a 
Python error, but a LaTeX error:


%! File ended while scanning definition of \filename@base. %
%}
% no pdf


If I am wrong, explain to me how you decided that this was a Python error 
rather than LaTeX. I've been using Python for over 15 years, and this is 
the first time I've seen anything even remotely like that. 

It is not clear to me whether "no pdf" is your comment, the output of 
pythontex, the output of LaTeX, or something else. It is also not clear 
whether % is literally part of the output, or just a 
placeholder for something you thought was irrelevant.


> 6) pythontex is a terrific package that I enjoy using 

Glad to hear it.


> 7) I was looking for help on debugging this error. 
> 8) I was trying to find out why I could not do \py{outfilename}

\py{outputfilename} isn't Python code, so I'm not sure why you think a 
Python forum is the right place to ask about this. For us to help you, 
we'll probably need to know:

- What is outputfilename?

- Are you sure it corresponds to an actual file? A readable file?
  (Check the permissions.) Containing the right output? E.g. if you're
  expecting a PDF file, but giving it a PNG file, it probably won't work.

- What Python code ends up being executed when you run \py
  {outputfilename}?

- Can you run that code successfully from Python itself, bypassing
  pythontex?

- If not, what result did you expect? What result did you get?

- If you got an exception, what was the entire exception?

- Any other relevant information that comes up while investigating.


Help us to help you. Excessively concise questions written for an 
audience who already knows everything you know is not likely to get a lot 
of help.


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


Functional Programming and python

2013-09-22 Thread rusi
Combining your two questions -- Recently:
What minimum should a person know before saying "I know Python"

And earlier this
On Sunday, August 4, 2013 10:00:35 PM UTC+5:30, Aseem Bansal wrote:
> If there is an issue in place for improving the lambda forms then that's 
> good. I wanted a link about functional programming because it is mentioned as 
> if it were a household word.

Python is not a functional programming language; however it supports most of FP 
better than traditional languages like C/Java.
eg with iterators/generators + itertools + functools you can do most of what 
lazy lists give in haskell

Some discussion here: 
http://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming

[Not everything said there is correct; eg python supports currying better than 
haskell which is surprising considering that Haskell's surname is Curry!]

So if I may break your question into two: 
1. Why should a programmer of a non-FP language know FP?
2. What in FP should a (any|all) programmer know?

I touched upon these in two blog-posts:
1. http://blog.languager.org/2013/06/functional-programming-invades.html
2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html

Also most programmers without an FP background have a poor appreciation of the 
centrality of recursion in CS; see
http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python, pythontex and plots

2013-09-22 Thread chitturk
1) The file is LaTeX
2) the % means LaTeX will ignore it.
3) The question was about using pythontex with LaTeX 
4) I included the file so you (OK, others) could see what I was trying
5) The problem had to do with accessing a file name within the python 
   script using \py{outputfile}
6) pythontex is a terrific package that I enjoy using
7) I was looking for help on debugging this error.
8) I was trying to find out why I could not do \py{outfilename}

On Sunday, September 22, 2013 7:58:59 PM UTC-5, Steven D'Aprano wrote:
> I don't usually top post, but for this I'll make an exception because I 
> 
> have *no idea* what any of your post means.
> 
> 
> 
> Are you actually asking a question? I can't see a question mark in it, so 
> 
> there's no explicit question. Are you just sharing something interesting 
> 
> you have learned? Expecting us to read your mind and intuit what the 
> 
> question is?
> 
> 
> 
> Why do nearly, but not quite all, the lines in your post start with % or 
> 
> \  or sometimes both? It looks like Postscript rather than Python.
> 
> 
> 
> Perhaps you should try again, and this time don't assume that we're 
> 
> familiar with whatever it is you're doing. Remember to include natural 
> 
> language explaining what your problem is, what result you expected, what 
> 
> result you actually got. In this forum, use English please. This is 
> 
> *especially* critical if using an unusual technology that most people are 
> 
> not familiar with.
> 
> 
> 
> I strongly recommend that first you read this:
> 
> 
> 
> http://sscce.org/
> 
> 
> 
> Its written for Java developers, but the same basic principles apply for 
> 
> Python. Remember that the number one language you should be using for 
> 
> communication is natural language (English in this forum) and code only 
> 
> second.
> 
> 
> 
> Thank you.
> 
> 
> 
> 
> 
> Steve
> 
> 
> 
> On Sun, 22 Sep 2013 13:26:06 -0700, chitturk wrote:
> 
> 
> 
> > \documentclass[12pt]{article}
> 
> > \usepackage{graphicx}
> 
> > \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex}
> 
> > \setpythontexworkingdir{.}
> 
> > \begin{document}
> 
> > 
> 
> > This is an example of using pythontex
> 
> > 
> 
> > \begin{pycode}
> 
> > 
> 
> > import pylab as p
> 
> > import numpy as np
> 
> > x = np.linspace(0.0,1.0,10)
> 
> > y = 2.0*x + 5.0
> 
> > xmax = max(x)
> 
> > ymax = max(y)
> 
> > p.plot(x,y)
> 
> > outputfile = 'myplot.png'
> 
> > p.savefig(outputfile)
> 
> > p.clf()
> 
> > 
> 
> > \end{pycode}
> 
> > 
> 
> > % this works fine, I can print the name of the output file, variables
> 
> > 
> 
> > The plot is named \py{outputfile}, the max in x was \py{xmax} and
> 
> > \py{ymax}
> 
> > 
> 
> > % now I would like to plot it, this works
> 
> > 
> 
> > \includegraphics[scale=0.75]{myplot.png}
> 
> > 
> 
> > % but when I do this
> 
> > 
> 
> > %\includegraphics[scale=0.75]{\py{outputfile}}
> 
> > 
> 
> > % I get
> 
> > 
> 
> > %! File ended while scanning definition of \filename@base. % 
> > text>
> 
> > %}
> 
> > % no pdf
> 
> > 
> 
> > 
> 
> > 
> 
> > \end{document}

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


Re: Directory Web Site

2013-09-22 Thread worthingtonclinton
On Sunday, September 22, 2013 9:59:14 PM UTC-4, Dave Angel wrote:
> On 22/9/2013 21:14, worthingtonclin...@gmail.com wrote:
> 
> 
> 
> > Was hoping to get some tips or advice on scripting a program that would 
> > sort through my many links on my directory website and print out to me the 
> > ones that are broken or no longer functioning so that I could fix or remove 
> > them from the site. Any help, ideas, advice will be greatly appreciated.
> 
> 
> 
> Since it's your own website, the best answer is probably to process the
> 
> source to that site. Was it written by a python script?
> 
> 
> 
> Otherwise, if the site is reasonably correct (as most are not), then
> 
> Beautiful Soup is probably the place to start.
> 
> 
> 
> -- 
> 
> DaveA

Web page is in HTML created using Dreamweaver.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Directory Web Site

2013-09-22 Thread worthingtonclinton
On Sunday, September 22, 2013 9:36:25 PM UTC-4, Joel Goldstick wrote:
> On Sun, Sep 22, 2013 at 9:14 PM,   wrote:
> 
> Was hoping to get some tips or advice on scripting a program that would sort 
> through my many links on my directory website and print out to me the ones 
> that are broken or no longer functioning so that I could fix or remove them 
> from the site. Any help, ideas, advice will be greatly appreciated.
> 
> 
> --
> 
> https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 
> This is a python list.  is this python related? what have you tried?  Do you 
> know about beautiful soup or requests?  they can help you I think.  You 
> really need to provide more information for any useful help here
> 
> 
> 
> 
> -- 
> 
> 
> Joel Goldstick
> http://joelgoldstick.com

I'm trying to create a Python script that will search through the url links on 
my directory website and using a logic statement like, if: (how ever i would 
establish in python that the url is not broken) then return, elsif: (link is 
broken) then: print '%s is broken.' (%s being the name of the link). I want the 
program to perform this on all the links so that I can easily see which links 
are useless on my website so my page doesn't wind up functionally being 
difficult and clouded with broken links like every other crappy directory. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Directory Web Site

2013-09-22 Thread Dave Angel
On 22/9/2013 21:14, worthingtonclin...@gmail.com wrote:

> Was hoping to get some tips or advice on scripting a program that would sort 
> through my many links on my directory website and print out to me the ones 
> that are broken or no longer functioning so that I could fix or remove them 
> from the site. Any help, ideas, advice will be greatly appreciated.

Since it's your own website, the best answer is probably to process the
source to that site. Was it written by a python script?

Otherwise, if the site is reasonably correct (as most are not), then
Beautiful Soup is probably the place to start.

-- 
DaveA


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


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread rusi
On Monday, September 23, 2013 12:27:50 AM UTC+5:30, John Ladasky wrote:
> All right, never mind!
> 
> 
> I hacked around this morning, making some changes to parts of my program that 
> I thought were unrelated to my namespace issues.  I was paring it down to a 
> minimal example, to post here as Ned requested.  As an experiment, I also 
> commented out the global declaration line in move_balls... and everything 
> worked this time.
> 
> 
> I'm baffled as to what necessitated the global declaration in the first 
> place.  But since the goal was to teach my students a graphical tool, I don't 
> think that I will investigate this matter any further.

Not related to your question but to turtle graphics
Have you seen this?
http://code.google.com/p/pynguin/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Directory Web Site

2013-09-22 Thread Joel Goldstick
On Sun, Sep 22, 2013 at 9:14 PM,  wrote:

> Was hoping to get some tips or advice on scripting a program that would
> sort through my many links on my directory website and print out to me the
> ones that are broken or no longer functioning so that I could fix or remove
> them from the site. Any help, ideas, advice will be greatly appreciated.
> --
> https://mail.python.org/mailman/listinfo/python-list
>


This is a python list.  is this python related? what have you tried?  Do
you know about beautiful soup or requests?  they can help you I think.  You
really need to provide more information for any useful help here


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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-22 Thread alex23

On 21/09/2013 11:29 PM, William Ray Wing wrote:

Νίκος ,
   You CLEARLY don't understand.


Just a public service reminder that Nikos' behaviour is _consistently_ 
that of his prefered nom de plume:


"Ferrous Cranus is utterly impervious to reason, persuasion and new 
ideas, and when engaged in battle he will not yield an inch in his 
position regardless of its hopelessness"


http://www.politicsforum.org/images/flame_warriors/flame_62.php

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


Directory Web Site

2013-09-22 Thread worthingtonclinton
Was hoping to get some tips or advice on scripting a program that would sort 
through my many links on my directory website and print out to me the ones that 
are broken or no longer functioning so that I could fix or remove them from the 
site. Any help, ideas, advice will be greatly appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python, pythontex and plots

2013-09-22 Thread Steven D'Aprano
I don't usually top post, but for this I'll make an exception because I 
have *no idea* what any of your post means.

Are you actually asking a question? I can't see a question mark in it, so 
there's no explicit question. Are you just sharing something interesting 
you have learned? Expecting us to read your mind and intuit what the 
question is?

Why do nearly, but not quite all, the lines in your post start with % or 
\  or sometimes both? It looks like Postscript rather than Python.

Perhaps you should try again, and this time don't assume that we're 
familiar with whatever it is you're doing. Remember to include natural 
language explaining what your problem is, what result you expected, what 
result you actually got. In this forum, use English please. This is 
*especially* critical if using an unusual technology that most people are 
not familiar with.

I strongly recommend that first you read this:

http://sscce.org/‎

Its written for Java developers, but the same basic principles apply for 
Python. Remember that the number one language you should be using for 
communication is natural language (English in this forum) and code only 
second.

Thank you.


Steve

On Sun, 22 Sep 2013 13:26:06 -0700, chitturk wrote:

> \documentclass[12pt]{article}
> \usepackage{graphicx}
> \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex}
> \setpythontexworkingdir{.}
> \begin{document}
> 
> This is an example of using pythontex
> 
> \begin{pycode}
> 
> import pylab as p
> import numpy as np
> x = np.linspace(0.0,1.0,10)
> y = 2.0*x + 5.0
> xmax = max(x)
> ymax = max(y)
> p.plot(x,y)
> outputfile = 'myplot.png'
> p.savefig(outputfile)
> p.clf()
> 
> \end{pycode}
> 
> % this works fine, I can print the name of the output file, variables
> 
> The plot is named \py{outputfile}, the max in x was \py{xmax} and
> \py{ymax}
> 
> % now I would like to plot it, this works
> 
> \includegraphics[scale=0.75]{myplot.png}
> 
> % but when I do this
> 
> %\includegraphics[scale=0.75]{\py{outputfile}}
> 
> % I get
> 
> %! File ended while scanning definition of \filename@base. % text>
> %}
> % no pdf
> 
> 
> 
> \end{document}

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


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-22 Thread alex23

On 20/09/2013 5:01 PM, William Bryant wrote:

I have one more question, is there any way I can make my program work on 
android tablets and ipads? Because I'd like to use it in school because we are 
learning statistics and we are allowed our devices in school.


I'd recommend taking a look at kivy, it supports both Android & iOS (as 
well as Windows, Mac, Linux):


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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-22 Thread Steven D'Aprano
On Sun, 22 Sep 2013 09:39:07 -0400, Ned Batchelder wrote:

> On 9/22/13 12:09 AM, Luca Cerone wrote:
>> Hi Chris,
>> actually my priority is to check that the code is correct. I changed
>> the syntax during the development, and I want to be sure that my
>> tutorial is up to date.
>>
>>
> If you do manage to ignore the output, how will you know that the syntax
> is correct?  The output for an incorrect syntax line will be an
> exception, which you'll ignore.  Maybe I don't know enough about the
> details of doctest.  It's always seemed incredibly limited to me.
> Essentially, it's as if you used unittest but the only assertion you're
> allowed to make is self.assertEqual(str(X), "")

More or less :-)

Doc tests really are documentation first and tests second. That's its 
strength. If you want unit tests, you know where to find them :-)


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


Re: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator.

2013-09-22 Thread Terry Reedy

On 9/22/2013 2:57 PM, bab mis wrote:

def funlog(f):
 def g(*args,**kw):
 print "enter", f.__name__
 try:
 return f(*args, **kw)
 finally:
 print "exit", f.__name__
 return g

class Action:
 def __init__(self):
 pass

 @funlog
 def sret(self):
 pass

 @funlog
 def ping(self):
 pass
 def verifyerun(self):
 pass


1) funlog is called for the last function as well.


If this is a question, no, it is not called on verifyerun.


2) Is it a proper way to define decorator out of class and use it .


Yes. It is not an Action methods. If you use it in multiple files, 
define once in one file and import it.


--
Terry Jan Reedy

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


python, pythontex and plots

2013-09-22 Thread chitturk
\documentclass[12pt]{article}
\usepackage{graphicx} 
\usepackage{wrapfig} % Allows in-line images
\usepackage{pythontex}
\setpythontexworkingdir{.}
\begin{document}

This is an example of using pythontex

\begin{pycode}

import pylab as p 
import numpy as np
x = np.linspace(0.0,1.0,10)
y = 2.0*x + 5.0
xmax = max(x)
ymax = max(y)
p.plot(x,y)
outputfile = 'myplot.png'
p.savefig(outputfile)
p.clf()

\end{pycode}

% this works fine, I can print the name of the output file, variables

The plot is named \py{outputfile}, the max in x was \py{xmax} and \py{ymax}

% now I would like to plot it, this works 

\includegraphics[scale=0.75]{myplot.png}

% but when I do this

%\includegraphics[scale=0.75]{\py{outputfile}}

% I get 

%! File ended while scanning definition of \filename@base.
% 
%}
% no pdf 



\end{document}
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What minimum should a person know before saying "I know Python"

2013-09-22 Thread Gene Heskett
On Sunday 22 September 2013 15:46:52 Gene Heskett did opine:

> On Sunday 22 September 2013 14:49:21 Dennis Lee Bieber did opine:
> > On Sat, 21 Sep 2013 02:22:59 -0400, Gene Heskett 
> > 
> > declaimed the following:
> > >I was quite pleased to see that there was a Rexx/Regina for linux,
> > >and for about 10 minutes thought I could make use of the library of
> > >ARexx code Jim & I had carved up and had running on the amiga, but
> > >was very disappointed to see that Regina wasn't coupled to the os
> > >itself in any way, causing our scripts to barf and exit within the
> > >first 3 or 4 lines of code.
> > >
> > No surprise given the lack of real /interactive/ IPC in Windows and
> > 
> > Linux. A version of REXX running on (Open)VMS might have a chance --
> > as VMS Mailboxes were a (protected memory equivalent) of Amiga
> > message ports... So a means of "address other_application" could be
> > mapped to opening "other_application_port".
> > 
> > I vaguely recall once using the "advanced" calls from the back of
> 
> the
> 
> > manual, and having multiple ARexx scripts talking to each other via
> > "address other_script"
> 
> We did that dozens of times a day on every machine we owned, which at
> the time was about just in the commercial production rooms.

s/about just/about 6 just/g

> > >I've seen python doing some heady stuff in the last 5 years, but the
> > >learning curve is pretty steep for my now aging wet ram, which will
> > >be 79 years old in a few days, so the scripting language here at the
> > >Heskett Ranchette is bash, and there is quite a boatload of that
> > >running as background daemons right now.  So I lurk, reading what
> > >goes by, hoping I'll learn enough python from osmosis to get
> > >comfortable with it.  From all indications, it is todays "ARexx" of
> > >scripting languages.
> > >
> > Having been spoiled by ARexx myself... No... Python will never be
> > 
> > /that/... Even subprocess.popen() doesn't allow for the easy control
> > of other programs. One is stuck with M$ COM (the win32 extension
> > library or, more portable maybe [if the libraries are ported] ctypes
> > to do what "address ..." did in ARexx.
> 
> Then it seems to me that work in the direction should be an active
> feature request.  Unforch, as I've said before, I'm rowing this barge
> with a toothpick for an oar. :)
> 
> I would be interesting to see if the "bait" is taken. :)
> 
> Thanks Dennis.
> 
> Cheers, Gene


Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page:  should be up!

Hate is like acid.  It can damage the vessel in which it is stored as well
as destroy the object on which it is poured.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread John Ladasky
All right, never mind!

I hacked around this morning, making some changes to parts of my program that I 
thought were unrelated to my namespace issues.  I was paring it down to a 
minimal example, to post here as Ned requested.  As an experiment, I also 
commented out the global declaration line in move_balls... and everything 
worked this time.

I'm baffled as to what necessitated the global declaration in the first place.  
But since the goal was to teach my students a graphical tool, I don't think 
that I will investigate this matter any further.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator.

2013-09-22 Thread bab mis
On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote:
> def fun:
> 
> print "entry"
> 
> .
> 
> .
> 
> print "


On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote:
> def fun:
> 
> print "entry"
> 
> .
> 
> .
> 
> print "exit"



On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote:
> def fun:
> 
> print "entry"
> 
> .
> 
> .
> 
> print "exit"




Peter couple of queries with following code :

def funlog(f):
def g(*args,**kw):
print "enter", f.__name__
try:
return f(*args, **kw)
finally:
print "exit", f.__name__
return g 

class Action:
def __init__(self):
pass

@funlog
def sret(self):
pass

@funlog
def ping(self):
pass
def verifyerun(self):
pass


1) funlog is called for the last function as well.
2) Is it a proper way to define decorator out of class and use it .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What minimum should a person know before saying "I know Python"

2013-09-22 Thread Gene Heskett
On Sunday 22 September 2013 14:49:21 Dennis Lee Bieber did opine:

> On Sat, 21 Sep 2013 02:22:59 -0400, Gene Heskett 
> 
> declaimed the following:
> >I was quite pleased to see that there was a Rexx/Regina for linux, and
> >for about 10 minutes thought I could make use of the library of ARexx
> >code Jim & I had carved up and had running on the amiga, but was very
> >disappointed to see that Regina wasn't coupled to the os itself in any
> >way, causing our scripts to barf and exit within the first 3 or 4
> >lines of code.
> 
>   No surprise given the lack of real /interactive/ IPC in Windows and
> Linux. A version of REXX running on (Open)VMS might have a chance -- as
> VMS Mailboxes were a (protected memory equivalent) of Amiga message
> ports... So a means of "address other_application" could be mapped to
> opening "other_application_port".
> 
>   I vaguely recall once using the "advanced" calls from the back of 
the
> manual, and having multiple ARexx scripts talking to each other via
> "address other_script"

We did that dozens of times a day on every machine we owned, which at the 
time was about just in the commercial production rooms.

> >I've seen python doing some heady stuff in the last 5 years, but the
> >learning curve is pretty steep for my now aging wet ram, which will be
> >79 years old in a few days, so the scripting language here at the
> >Heskett Ranchette is bash, and there is quite a boatload of that
> >running as background daemons right now.  So I lurk, reading what goes
> >by, hoping I'll learn enough python from osmosis to get comfortable
> >with it.  From all indications, it is todays "ARexx" of scripting
> >languages.
> 
>   Having been spoiled by ARexx myself... No... Python will never be
> /that/... Even subprocess.popen() doesn't allow for the easy control of
> other programs. One is stuck with M$ COM (the win32 extension library
> or, more portable maybe [if the libraries are ported] ctypes to do what
> "address ..." did in ARexx.

Then it seems to me that work in the direction should be an active feature 
request.  Unforch, as I've said before, I'm rowing this barge with a 
toothpick for an oar. :)

I would be interesting to see if the "bait" is taken. :)

Thanks Dennis.

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page:  should be up!

Real programmers don't write in BASIC.  Actually, no programmers write in
BASIC after reaching puberty.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Animations and images with use for commercial license

2013-09-22 Thread Terry Reedy

On 9/22/2013 1:09 PM, and...@zoho.com wrote:


I am designing a roleplay game, right now i think i might go into the
anime direction and style it accordingly... how do i get animations
and images to give it a nice feeling. Where do you get your graphics
from for such kind of games do you paint them yourself?


This is not really a Python question. You might do better on the pygame 
list or a more general game developer forum.


--
Terry Jan Reedy

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


Animations and images with use for commercial license

2013-09-22 Thread andypu
Hello all,

I am designing a roleplay game, right now i think i might go into the anime 
direction and style it accordingly... how do i get animations and images to 
give it a nice feeling. Where do you get your graphics from for such kind of 
games do you paint them yourself?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-22 Thread Luca Cerone
On Sunday, 22 September 2013 14:39:07 UTC+1, Ned Batchelder  wrote:
> On 9/22/13 12:09 AM, Luca Cerone wrote:
> 
> > Hi Chris,
> 
> > actually my priority is to check that the code is correct. I changed the 
> > syntax
> 
> > during the development, and I want to be sure that my tutorial is up to 
> > date.
> 
> >
> 
> 
> 
> If you do manage to ignore the output, how will you know that the syntax 
> 
> is correct?  The output for an incorrect syntax line will be an 
> 
> exception, which you'll ignore.

if the function raises an exception, the test fails, regardless of the output

>  Maybe I don't know enough about the 
> 
> details of doctest.  It's always seemed incredibly limited to me.  

I agree that has some limitations

> 
> Essentially, it's as if you used unittest but the only assertion you're 
> 
> allowed to make is self.assertEqual(str(X), "")
> 
> 

I don't know unittest, is it possible to use it within Sphinx?

> 
> --Ned.

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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-22 Thread Luca Cerone
> This makes no sense. If you ignore the output, the code could do ANYTHING 
> 
> and the test would still pass. Raise an exception? Pass. SyntaxError? 
> 
> Pass. Print "99 bottles of beer"? Pass.
> 

if you try the commands, you can see that the tests fail..
for example

.. doctest::

   >>> raise Exception("test")

will fail with this message: 

File "utils.rst", line 5, in default
Failed example:
raise Exception("test")
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 1289, in __run
compileflags, 1) in test.globs
  File "", line 1, in 
raise Exception("test")
Exception: test

So to me this seems OK.. "Print" will fail as well...

> 
> 
> I have sometimes written unit tests that just check whether a function 
> 
> actually is callable:
> 
> 
> 
> ignore = function(a, b, c)
> 
> 
> 
> but I've come to the conclusion that is just a waste of time, since there 
> 
> are dozens of other tests that will fail if function isn't callable. But 
> 
> if you insist, you could always use that technique in your doctests:
> 
> 
> 
> >>> ignore = function(a, b, c)
> 
> 
> If the function call raises, your doctest will fail, but if it returns 
> 
> something, anything, it will pass.
> 
> 

I understand your point, but now I am not writing unit tests to check the 
correctness of the code. I am only writing a tutorial and assuming that
the code is correct. What I have to be sure is that the code in the tutorial
can be executed correctly, and some commands print verbose output which can 
change.

It is not enough to write >>> ignore = function(a,b,c) won't work because the 
function still prints messages on screen and this causes the failure of the 
test...

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


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread Nobody
On Sat, 21 Sep 2013 21:39:07 -0700, John Ladasky wrote:

> However, neither Screen.ontimer() not Screen.onkeypress() appear to give
> me a way to pass arguments to functions of my own.  Why don't they?  Is
> this some limitation of Tk?  I have worked with other GUI's before, and I
> don't remember having to jump through this particular hoop.

The usual approach in Python is to pass a bound method of an object, and
keep all of the data on that object.

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


Re: reload and work flow suggestions

2013-09-22 Thread rusi
On Sunday, September 22, 2013 3:13:13 AM UTC+5:30, Peter Cacioppi wrote:
> This is an idea brought over from another post.
> 
> When I write Python code I generally have 2 or 3 windows open simultaneously.
> 
> 
> 1) An editor for the actual code.
> 2) The interactive interpreter.
> 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts)
> 
> My work flow tends to involve using 2 to debug the issues that come up with 1 
> and 3. I'll write some new code in 1, play around with it in 2, then solidify 
> the tests in 3. Or a test in 3 fails and I dig around with it using 2.
> 
> 
> 
> My problem is that I tend to use reload() quite a bit. I want to call 
> functions and construct objects that are inside the guts of 1 and pass them 
> arguments that are stored as variables in 2. If I restart my session for 2 I 
> lose these variables (iPython does mitigate the pain here somewhat). Hence, I 
> reload() modules into 2 when they are changed.

I (tend to) use emacs.

Now before this becomes an editor-war, I need to say that its hardly a question 
of editor and mostly a question of workflow.  For example I know some core 
emacs devs who use vi-mode in emacs and as the joke goes:

Emacs is an excellent operating system; it only lacks a good editor.

About workflow: Its important to get that

1. editor-inside-interpreter -- eg !vi in ipython
2. interpreter-and-editor side-by-side -- your workflow
3. interpreter-inside-editor -- natural for emacs and IDLE (I think)
are significantly different

And one important difference is that for 3. the burden of reload goes from 
python to the editor -- one hotkey and the buffer is reloaded into the 
interpreter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-22 Thread Ned Batchelder

On 9/22/13 12:09 AM, Luca Cerone wrote:

Hi Chris,
actually my priority is to check that the code is correct. I changed the syntax
during the development, and I want to be sure that my tutorial is up to date.



If you do manage to ignore the output, how will you know that the syntax 
is correct?  The output for an incorrect syntax line will be an 
exception, which you'll ignore.  Maybe I don't know enough about the 
details of doctest.  It's always seemed incredibly limited to me.  
Essentially, it's as if you used unittest but the only assertion you're 
allowed to make is self.assertEqual(str(X), "")


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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-22 Thread Steven D'Aprano
On Sat, 21 Sep 2013 21:15:48 -0700, Luca Cerone wrote:

> I am looking for a way to test the code while ignoring the output.

This makes no sense. If you ignore the output, the code could do ANYTHING 
and the test would still pass. Raise an exception? Pass. SyntaxError? 
Pass. Print "99 bottles of beer"? Pass.

I have sometimes written unit tests that just check whether a function 
actually is callable:

ignore = function(a, b, c)

but I've come to the conclusion that is just a waste of time, since there 
are dozens of other tests that will fail if function isn't callable. But 
if you insist, you could always use that technique in your doctests:

>>> ignore = function(a, b, c)

If the function call raises, your doctest will fail, but if it returns 
something, anything, it will pass.


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


Re: [Savoynet] My sorrow, that I may share it with you

2013-09-22 Thread Chris Angelico
On Sun, Sep 22, 2013 at 8:25 PM, Steven D'Aprano
 wrote:
> On Sun, 22 Sep 2013 19:32:49 +1000, Chris Angelico wrote:
>
>> On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE
>>  wrote:
>>> Seriously, folks - a performing group which calls itself a Gilbert and
>>> Sullivan Society but doesn't perform Gilbert and Sullivan is in the
>>> same category as a fool who doesn't follify or a cock who doesn't crow,
>>> and should get the same treatment.  I believe there are lots of nice
>>> rivers in British Columbia?
>>
>> These Societies stand on a similar basis to Limited Liability Companies,
>> though. You may wind them up, you cannot conveniently put concrete
>> blocks on their feet, blow them up with dynamite, and have them land in
>> The Canal...
>
> Try this:
>
> import dirtydeeds
>
> muscle = dirtydeeds.hire()
> muscle.concrete_shoes(performance_group)
> muscle.dynamite.explode(performance_group)
> remains = muscle.collect(performance_group)
> muscle.dump(remains, "The Canal")
>
>
> It's not free software (free as in beer), but I'm told that it is dirt
> cheap...

I would also recommend:

del gmail

except that I haven't gotten around to finding a replacement. So I
managed instead to mix two different forms of humour (Gilbert &
Sullivan, and the Goon Show), and post it to a place that shares a
name with a third (Python)...

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


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread Ned Batchelder

On 9/22/13 12:39 AM, John Ladasky wrote:

For a while, I had a "quit" function that I bound to the q key:

sc.onkeypress(quit, "q")

The quit function simply printed a message, and then called sc.bye().  As with 
move_balls, quit wouldn't work unless I had a "global sc" declaration in it.  
(My shortened program skips my function and just binds sc.bye to the q key, avoiding the 
need for globals.)


It sounds like you didn't need as many global statements as you think.  
In particular, you only need to use "global" if you are assigning to a 
global name within a function.  The quit function you describe didn't 
have a "sc = ..." statement in it, and so should not have needed a 
"global sc" statement.


Can you show the code with the global statements?  There's very likely a 
way to get rid of some of them.


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


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread Steven D'Aprano
On Sat, 21 Sep 2013 21:39:07 -0700, John Ladasky wrote:

> Hi, folks,
> 
> Some of you may remember that I am teaching some high school students
> how to program.  Because they all love graphics, I have been
> investigating the turtle module, which I gather is built on top of Tk. 
> I can see that real-time applications are possible.  I'm writing a
> classic "bouncing-balls" program to demonstrate to my students.
> 
> In the main program code, I instantiate a turtle.Screen, named sc.
> 
> I draw a bounding box, whose size is described by the variables edgew
> and edgeh.  I have a list of Turtle objects, which I named balls.  I
> have a timer interval stored in tick.
> 
> In the main loop of my program, I bind a function to update the
> positions of the balls to a timer, thus:
> 
> sc.ontimer(move_balls, tick)
> 
> Inside my move_balls function, I could not get ANYTHING done without the
> following declaration:
> 
> global balls, edgew, edgeh, tick

That doesn't sound right. You don't need to declare globals unless you 
are rebinding them (assigning to the name). So if you do something like 
this:

def move_balls():
for ball in balls:
do_something_with(ball)


you're not assigning to global "balls" so no global declaration is 
needed. But if you do this:


def move_balls():
balls = sorted(balls)  # say
for ball in balls:
do_something_with(ball)


then you need a global declaration since you're assigning to the global 
variable. Likewise for tick, edgew and edgeh -- if you're just *reading* 
their value, you don't need to declare them.


> For a while, I had a "quit" function that I bound to the q key:
> 
> sc.onkeypress(quit, "q")
> 
> The quit function simply printed a message, and then called sc.bye(). 
> As with move_balls, quit wouldn't work unless I had a "global sc"
> declaration in it.

Again, that sounds wrong. This should work, since sc is not assigned to:

def quit():
print("Bye now!")
sc.bye()


If that's not the case, there's something you're not telling us about 
your code. Actual working examples are appreciated.




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


Re: [Savoynet] My sorrow, that I may share it with you

2013-09-22 Thread Steven D'Aprano
On Sun, 22 Sep 2013 19:32:49 +1000, Chris Angelico wrote:

> On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE
>  wrote:
>> Seriously, folks - a performing group which calls itself a Gilbert and
>> Sullivan Society but doesn't perform Gilbert and Sullivan is in the
>> same category as a fool who doesn't follify or a cock who doesn't crow,
>> and should get the same treatment.  I believe there are lots of nice
>> rivers in British Columbia?
> 
> These Societies stand on a similar basis to Limited Liability Companies,
> though. You may wind them up, you cannot conveniently put concrete
> blocks on their feet, blow them up with dynamite, and have them land in
> The Canal...

Try this:

import dirtydeeds

muscle = dirtydeeds.hire()
muscle.concrete_shoes(performance_group)
muscle.dynamite.explode(performance_group)
remains = muscle.collect(performance_group)
muscle.dump(remains, "The Canal")


It's not free software (free as in beer), but I'm told that it is dirt 
cheap...



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


Re: Antispam measures circumventing

2013-09-22 Thread Jugurtha Hadjar

On 09/20/2013 08:02 PM, Joel Goldstick wrote:



Last year I was playing around with django forms and wrote some code
that required the user to add some numbers before the form was
submitted. Here is the article:
http://www.joelgoldstick.com/blog/2012/sep/30/django-forms/

This isn't exactly what you are asking, but it does give you a change to
let someone send you mail without giving out your email address.



Still interesting. Anything to fight spam. I was thinking more about 
when your e-mail address is out there (in mailing lists, for example).


Some lists do the effort to at least do the (dot) and (at) kung fu to 
hide your address to a certain degree. Others just put it as a 
low-hanging fruit, in ole' plain text, ready to harvest.


I joined my e-mail address in the code comment, that's why I was 
thinking that way.




With the onslaught of social media stuff, it feels like sites like
linked in and anything that uses gmail want to get you to give away your
email address, and perhaps give access to everyone in your lists. So,
I'm suggesting its really a loosing battle.



You don't say! There's a Firefox add-on called "Collusion" that shows 
how websites exchange your data between them and let me tell you: It's 
not reassuring.



--
Joel Goldstick
http://joelgoldstick.com



--
~Jugurtha Hadjar,
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Savoynet] My sorrow, that I may share it with you

2013-09-22 Thread Chris Angelico
On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE  wrote:
> Seriously, folks - a performing group which calls itself a Gilbert and
> Sullivan Society but doesn't perform Gilbert and Sullivan is in the same
> category as a fool who doesn't follify or a cock who doesn't crow, and
> should get the same treatment.  I believe there are lots of nice rivers in
> British Columbia?

These Societies stand on a similar basis to Limited Liability
Companies, though. You may wind them up, you cannot conveniently put
concrete blocks on their feet, blow them up with dynamite, and have
them land in The Canal...

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


Re: Why do I have to use "global" so much when using Turtle?

2013-09-22 Thread Peter Otten
John Ladasky wrote:

> Hi, folks,
> 
> Some of you may remember that I am teaching some high school students how
> to program.  Because they all love graphics, I have been investigating the
> turtle module, which I gather is built on top of Tk.  I can see that
> real-time applications are possible.  I'm writing a classic
> "bouncing-balls" program to demonstrate to my students.
> 
> In the main program code, I instantiate a turtle.Screen, named sc.
> 
> I draw a bounding box, whose size is described by the variables edgew and
> edgeh.  I have a list of Turtle objects, which I named balls.  I have a
> timer interval stored in tick.
> 
> In the main loop of my program, I bind a function to update the positions
> of the balls to a timer, thus:
> 
> sc.ontimer(move_balls, tick)
> 
> Inside my move_balls function, I could not get ANYTHING done without the
> following declaration:
> 
> global balls, edgew, edgeh, tick

That's not limited to turtle, Python in general forces you to make shared 
state explicit. 

Simple alternatives to global would be a degenerate class

class state:
pass

or a magic import

import __main__ as state

With both of these (pseudo-)globals can be set with

state.some_global = some_value

However, most of the names you list above look like their values need not be 
altered from within the function and thus the name not be declared global 
anyway. To be sure you'd have to show us the code...



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