[Tutor] way of dictating leading zeros

2009-03-15 Thread Patrick
Hi Everyone

I am trying to write a program that creates a bunch of svg files and
then edits their values. I am then encoding them into a video. It's not
encoding right because my filenames are wrong. They have to have a
sequence. Right now they are 1.svg, 2.svg, 3.svg etc but they should be
001.svg, 002.svg, 003.svg. At the moment I think 12.svg is ending up
before 2.svg because it starts with 1.

Is there an easy way to dictate how many digits a number will occupy
that also allows for leading zeros?

Below is a sample of my code if it helps:

Thanks in advance-Patrick


def thingcreate():
thingfile = raw_input("Enter full pathname of your template: ")
thingseconds = raw_input("Enter how many seconds your film will be: ")
thingseconds =int(thingseconds)
thingframes = raw_input("Enter how many frames per second your film
will be: ")
thingframes =int(thingframes)
thingnumber = thingframes * thingseconds
f = open(thingfile, 'r')
thingread = f.read()
for i in range(thingnumber):
i = str(i)
file =open(i+".svg", 'w')
file.write(thingread)
file.close()   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] include remote module

2009-09-12 Thread Patrick
Strange question.

Is it possible to include a module that is on another computer?

I have been day-dreaming about a project that would allow web code to
drive a desktop App.

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


Re: [Tutor] include remote module

2009-09-12 Thread Patrick
Hi Wayne

Thanks for your help. I was thinking of the latter but now that I think
of it, once you import a module it won't help to modify that module on
the fly later anyways, right?  I would need to re-import it. Sounds like
reading it via http would be simpler.

Thanks again-Patrick

Wayne wrote:
> On Sat, Sep 12, 2009 at 7:55 AM, Patrick  <mailto:optoma...@rogers.com>> wrote:
>
> Strange question.
>
> Is it possible to include a module that is on another computer?
>
> I have been day-dreaming about a project that would allow web code to
> drive a desktop App.
>
>
> I know of one way, using sshfs, which allows you to mount an ssh
> location as a directory on your computer. Then it would effectively be
> a local filesystem. I don't know if there's something like that on
> Windows.
>
> Of course, what do you mean when you say "web code to drive a desktop
> app"? Do you mean you want to host some code that others can connect
> to that will change? Or do you mean you want people to connect to your
> server and it will run an app on your desktop?
>
> For the former it's not really necessary to include the mod on another
> computer. Just use the http libraries and download the file when the
> script runs. Then import it.
>
> HTH,
> Wayne

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


Re: [Tutor] include remote module

2009-09-12 Thread Patrick
Hey Patrick

What I great idea. I did not even know about the compile function. Maybe
this idea could really work.

Imagine if I gave a client a live Linux CD that automatically called
this sort of script right after boot up. They could have the absolute
most current version of an application from my server launched on their
box and if their data from that application was re-uploaded back to the
server they would have a desktop application with persistence and
assuming the hard drive was not mounted in the process(or it was but
they could trust me), they would also have fairly secure environment to
work in. It would not be perfect yet but it would be safer then using
closed source applications.

Thanks again and thanks to Rich, Allan and Wayne too-Pat

Patrick Sabin wrote:
> Maybe something like this helps you to solve your problem:
>
> # get code via http, etc.
> code = """
> def blah():
> print 'blah'
>
> print 'hello'
> blah()
> """
>
> compiled_code = compile(code, 'filename', 'exec')
> exec(compiled_code)
>
> This way you could execute some code from a web client, but the client
> would be able to execute any code, he could even delete your hard drive.
>
> - Patrick
>
> Patrick schrieb:
>> Hi Wayne
>>
>> Thanks for your help. I was thinking of the latter but now that I think
>> of it, once you import a module it won't help to modify that module on
>> the fly later anyways, right? I would need to re-import it. Sounds like
>> reading it via http would be simpler.
>>
>> Thanks again-Patrick
>>
>> Wayne wrote:
>>> On Sat, Sep 12, 2009 at 7:55 AM, Patrick >> <mailto:optoma...@rogers.com>> wrote:
>>>
>>> Strange question.
>>>
>>> Is it possible to include a module that is on another computer?
>>>
>>> I have been day-dreaming about a project that would allow web code to
>>> drive a desktop App.
>>>
>>>
>>> I know of one way, using sshfs, which allows you to mount an ssh
>>> location as a directory on your computer. Then it would effectively be
>>> a local filesystem. I don't know if there's something like that on
>>> Windows.
>>>
>>> Of course, what do you mean when you say "web code to drive a desktop
>>> app"? Do you mean you want to host some code that others can connect
>>> to that will change? Or do you mean you want people to connect to your
>>> server and it will run an app on your desktop?
>>>
>>> For the former it's not really necessary to include the mod on another
>>> computer. Just use the http libraries and download the file when the
>>> script runs. Then import it.
>>>
>>> HTH,
>>> Wayne
>>
>> ___
>> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-07 Thread Patrick
I am not sure if I can add to the excellent advice you have received
here but I would like to add my 2 cents.

I have learned a few languages over the past couple of years but I still
don't think I am a very good programmer. Please don't fall into the trap
I am in. I am now trying to learn more about programming strategies not
just another language. I have not received the book yet but I ordered
software systems development:

 
http://www.abebooks.com/servlet/BookDetailsPL?bi=1386620426&searchurl=isbn%3D0077111036

I am teaching myself UML to understand how to layout a blueprint and I
am trying to learn metamodeling concepts.

If you can spell really well and your grammar is perfect you still might
not be able to write a novel. Just learning a programming language is
not enough.

Hope this helps, I have certainly received more then my share of help
from this list-Patrick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hello and newbie question about "self"

2008-02-03 Thread Patrick
Hi guru's,

New to the list. I bought O'Reilly's Learning Python (3rd edition for
2.5) a while back. Slowly making my way through it and was pleasantly
surprised that Python seems easier than C. Until...I bumped into the
"self" thingy.

Can anyone please point me to a document that explains "self" in
layman's terms. Or lacking such a doc throw in a much appreciated
layman's explanation what "self" is and when/where to use it? 

In the book (so far) I've seen "self" pop up in these examples (on pages
457 and 458):

class C1(C2, C3):
def setname(self, who)
self.name = who

class C1(C2, C3):
def __init__(self, who)
self.name = who

Thanks for any pointers!

Regards,
Patrick

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello and newbie question about "self"

2008-02-03 Thread Patrick
Hi Alan,

Alan Gauld wrote:
> "Patrick" <[EMAIL PROTECTED]> wrote 
> 
>> Can anyone please point me to a document that explains "self" in
>> layman's terms. 
> 
> Try the OOP topic inmy tutorial...

Thanks will have a look.

>> Or lacking such a doc throw in a much appreciated
>> layman's explanation what "self" is and when/where to use it? 
> 
> Others have given code samples but a conceptuial explanation 
> is that 
> a) self is only used in OO programming within metjhods of a class.

Now that really helps. I was wondering about that and this answers it.

> b) self refers to the actual instance of the object receiving the 
> message with caused the method to be invoked.

This and reading chapter 23 in the book makes things much clearer now.
Thanks!

> Thus if we have a class C with a method m and 3 instances 
> a,b and z then when we invoke a.m() self will refer to a and 
> when we invoke b.m() self will refer to b. This means that the 
> innards of the method can use self to access the instance 
> specific data for that invocation.

Even more clear now :)

> If you have used C++ at all you might recognise it as the 
> same as 'this' in C++ except that in Python you must explicitly 
> specify it whereas C++ creates 'this' magically behind the scenes.

Last time I used C++ was (iirc) in 1987 with a Borland product. I recall
"this" and remember I got stuck on it then too.

> See my tutorial for more on this under the heading 
> "Using classes".

Will do. Thanks for the pointer.

> If you haven't started writing classes yet, you can safely ignore 
> it for now!

I probably won't need to start writing classes but I really want to
finish the book before I start coding something. I have a small script I
did in (horrible) bash and look forward to try to implement it in (less
horrible) Python.

Thanks for your help.

Regards,
Patrick




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello and newbie question about "self"

2008-02-03 Thread Patrick
Hi Michael,

Michael Langford wrote:
> In C, you may have "objectorientedesque" code like the following;
> 
> struct net {
> int foo;
> int bar;
> int baz;
> };
> 
> 
> void populate_net( struct net* mynet, int fooval, int barval)
> {
>   mynet->foo = fooval;
>   mynet->bar = barval;
>   mynet ->baz = fooval * 5;
> }
> 
> int connect_to_net(struct net* mynet)
> {
>  return  open_internet_connection(mynet->foo);
> }
> 
> int main (void)
> {
>   struct net inet;
>   populate_net(&inet,2,2);
> 
>   int returncode = connect_to_net(&inet);
>   printf("%d\n",returncode);
> }

Heh I had to grab my C book and browse up on structs and pointers to get 
  an idea what this was all about :)

> In that batch of C code, you manipulate the struct without fiddling
> with its fields in the user code. You let the functions change its
> values so that they are done correctly.

Ok that makes sense.

> In python, you are doing something similar. However, they make some
> syntactic sugar to make it so you don't have to pass the object in
> explicily. That is what self is.

Got it.

> So the analgous python code is:
> 
> 
> class net(object):
>def __init__(self,fooval,barbal):
>self.foo = fooval
>self.bar = barval
>self.baz = fooval*5
> 
> def connect_to(self):
>return open_internet_connection(self.foo)
> 
> 
> inet = net(2,2)
> returncode = inet.connect_to()
> print returncode
> 
> See how you don't have to pass in the inet object in? Instead you call
> it with the inet.connect_to() function, and the object itself is
> passed in explicitly as self?

Aaah starting to understand now.

> That's all it is.
> 
> Btw, make sure to always include "self". Otherwise you'll be writing a
> class method and it doesn't work the same way.

Thanks for the elaborate explanation!

Regards,
Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello and newbie question about "self"

2008-02-03 Thread Patrick
Hi Kent,

Kent Johnson wrote:
> Patrick wrote:
>> Hi guru's,
>>
>> New to the list. I bought O'Reilly's Learning Python (3rd edition for
>> 2.5) a while back. Slowly making my way through it and was pleasantly
>> surprised that Python seems easier than C. Until...I bumped into the
>> "self" thingy.
> 
> This should be covered by any tutorial. 2nd edition of Learning Python 
> has a section called Methods that introduces self. Also see

Yes it does but all was not clear after I finished the first part 
(chapter 22 in my 3rd edition). Just read chapter 23 and things are 
clearer now. Luckily the start of chapter 24 mentions that it's no big 
deal if I didn't understand everything because they will dive deeper 
into it explaining more.

> http://www.ibiblio.org/swaroopch/byteofpython/read/self.html
> http://hetland.org/writing/instant-hacking.html

Thanks for the links. Will read them when I have some spare cycles.

Regards,
Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python web documentation ( without frameworks?)

2008-06-24 Thread Patrick

Hi Everyone

This is my first post here. I would like to switch from php/mysql to 
python(mod_python) and postgresql. There are several recent books on 
cherrypy, django and turbogears but for some reason I just don't want to 
use a framework. Are there any current books you could recommend for 
general python web programming? Most of the general web programming 
books seem to be from 2004 or before.


Thanks-Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python web documentation ( without frameworks?)

2008-06-25 Thread Patrick

Thanks guys for responding to my post.

I did buy a book on turbogears today and I am watching some screencasts 
as well, I don't want to be ignorant of frameworks.


I don't think anyone could argue that working without a framework is 
better for the majority of people, I can clearly see the value of 
frameworks. However the idea of having a bunch of directories that I 
don't understand does not appeal to me, and learning a framework 
specific way of working with MySql, Postgresql etc rather then their 
native manner won't help me to transfer that knowledge into other areas 
such as desktop applications or other languages such as C.


I have been working with PHP and I don't really like it. However there 
is tons of code out there that I can copy, paste and modify, I don't 
need to re-invent the wheel, just modify it for my own needs. This does 
not seem to be the case with mod_python code.


Would it be logical for me to take python cgi code and rework it for 
mod_python? The two don't seem that different, am I wrong about this?


Kent was saying that working without a framework would be fairly 
primitive, are there features I just can't get without a framework? If 
so why is this? Is a framework not just a collection of off the shelf 
technologies bundled into a slick package? Can I not access the same 
features without a framework?


Am I the only one who wants an end-to-end understanding of my web app? 
Am I crazy? I am feeling a bit alienated here-Patrick



ALAN GAULD wrote:

Forwarding to list.
Please use Reply All when reponding to posts.

- Forwarded Message 
From: Jeff Johnson <[EMAIL PROTECTED]>
To: Alan Gauld <[EMAIL PROTECTED]>
Sent: Wednesday, 25 June, 2008 9:51:33 PM
Subject: Re: [Tutor] python web documentation ( without frameworks?)

This was crazy.  The presenter at our Python user group last night left 
everything at home.  So he proceeded to borrow someone's laptop, 
download and install Python and web.py (http://webpy.org/) and we all 
went through building the demo which displayed records in an SQLite 
table and allowed you to add one and redisplay.  I have used Django and 
web.py works pretty much the same way using templates and all, but 
web.py is significantly "lighter".


You might want to install web.py and go through the demo.  Put it in a 
folder called "deleteme" and you can just delete the folder if you're 
not interested.


Alan Gauld wrote:
  

"Patrick" <[EMAIL PROTECTED]> wrote


cherrypy, django and turbogears but for some reason I just don't want 
to use a framework. Are there any current books you could recommend 
for general python web programming? Most of the general web 
programming books seem to be from 2004 or before.
  

There's a good reason for that! Vanilla CGI - the most basic web
programming mechanism available is a rsource hog, non scaleable
and very hard to maintain beyiond small trivial projects. So people
have moved to Frameworks which offer better performance,
easier implementation and far better maintainablility. All Frameworks
aim to achieve that, the choice is pretty much a personal prefernce.

The good news is that if you want to continuously reinvent the wheel
by using vanilla CGI the books from 2004 will all pretty much still work.
CGI hasn't changed much and neither have the core web modules in
Python.

HTH,



  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] graphs & diagrams in python

2008-07-04 Thread Patrick

Hey Monika

How about Matplotlib AKA Pylab?
http://matplotlib.sourceforge.net/
-Patrick

Monika Jisswel wrote:

Hi Again,

What is the best library for drawing graphs & diagrams to ilustrate 
some statistics ?





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Firstrade Authentication ...

2008-08-03 Thread Patrick

Kent Johnson wrote:
[snip]


params = dict(username='janezfedero', password='kmet500', destination='')


I hope this is a fake username & password

Regards,
Patrick

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My experience on web.py / CherryPy

2008-08-04 Thread Patrick
I am in the same situation as you. I was looking at Django and 
Turbogears. I have finally settled on CherryPy, which is also built into 
Turbogears.


Watching this Google talk on Youtube:
http://www.youtube.com/watch?v=p-WXiqrzAf8

it seemed to me that Django is well suited for a developer team but is a 
bit sketchy when you try to scale it down to a single developer.


CherryPy seems to work well as a substitute for all-in-one-page CGI 
scripts without the respawning issues or as a proper MVC web application 
server.


I set up an account at Webfaction. They specialize in Python hosting and 
you can set up Turbogears, Django, CherryPy etc with a click of a button.


I would love to keep this thread going, please feedback as you move 
along, I feedback too


-patrick




ammar azif wrote:

Hi,

I am writing this to tell my experience on web.py. Two weeks ago, I 
was looking for a python web framework that is simple, 
straight-forward, easy to use and powerful at the same time. Django  
stood out as the most popular when I googled. I tried to use django 
but I found that the framework hides alot of things from me and files 
are generated by the framework  automaticaly and I felt like I wasnt 
in control. I know that django is powerful, but the learning curve is 
too steep for me and  I need to develop my app as soon as possible. I 
decided to give web.py a try and I found that the framework is easy to 
use and it gives a lot of control to the developer when handling GET 
and POST request and all these can be done in a single source code and 
using this framework has taught me a lot of low level web application 
programming basics. I might be wrong as I havent try django or any 
other frameworks yet. Hope python gurus here can share their thoughts 
on these matters, 





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My experience on web.py / CherryPy

2008-08-04 Thread Patrick

Oh oh, I did not mean to slag Django!

I was basing this on the talk given by Jacob Kaplin-Moss(one of the 
developers). He gave a great talk but became a bit evasive when he was 
questioned about Django scaling down to a single developer, specifically 
when he was questioned about the template views portion.


"IT SEEMED"

I am not qualified to give advice on Django, sorry if I ticked off anyone!

Anyone here using CherryPy? Did anyone consider it and then pass on it?

-Patrick

Kent Johnson wrote:

On Mon, Aug 4, 2008 at 2:22 PM, Patrick <[EMAIL PROTECTED]> wrote:

  

it seemed to me that Django is well suited for a developer team but is a bit
sketchy when you try to scale it down to a single developer.



Why do you say that? Django works fine with a single developer.

Kent

  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] importing strings

2008-09-11 Thread Patrick
I would like to import a string with a "placeholder" in it.

for example  "this is a %s"

I would then like to insert the value into it after importation, "this
is a %s" (test)

I have been able to import a string from another module threw a
dictionary but I can't seem to figure out how to do it so that I can
insert a value into the %s placeholder afterwards.

I can send over more code if this is an incomplete description.

Thanks in advance-Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PySQLite vs SQLalchemy

2008-09-12 Thread Patrick
I guess I am a Python framework burnout. I have tried so many of them
over the past two months, they are just not right for me right now. I am
trying to put together a program to generate my website offline via the
MVC paradigm, all I need to deal with is lots of static data.
 
I like SQLite, it's really easy to work with. I would like to model my
database in it natively but I am having quite a bit of trouble mapping
the variables in the SQLIte database via PySQLite. It appears that this
sort of thing is SQLalchemy's strong suit. However I would prefer not to
model my data base in it.

So, I am just wondering if anyone has any feedback with regard to
PySQLite and SQLalchemy. Is mapping the variables from the a database
via PySQLite a common problem? Is SQLalchemy being used for desktop
Applications? I bought a book on SQLalchemy but PySQLite seems to have
sparse documentation. We can build Python with SQLite built right in,
why is there not more documentation?

Thanks in advance-Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PySQLite vs SQLalchemy

2008-09-13 Thread Patrick
Thanks Alan, Jeff and John!

I am have been so impressed with the responses and response times I get
from this list. I wish I could compensate you for your time(I'm broke at
the moment), you just can't buy this "customer service" anywhere else.
Hopefully when I am further along I can "man the fort" and help others
too. I registered pythonwebprogramming.org, I hope to post tutorials
here someday. I have had a bit of a rough go with it, hopefully I can
help others later when I know what I am doing.

Hey Jeff
" I would prefer not to model my data base in it."
>
> I'm curious why you feel that way?

I guess I might still end up doing so, it's just that SQLite was
immediately intuitive to me. Thanks for your SQLAlchemy feedback!


Hi John

"Have you taken a look at pylons? "
Yes, Pylons, CherryPy, Mod_Python, Django, Turbogears, Werkzeug and
WebPy. I know I am a small minority but frameworks are really counter to
my philosophy. I am a beginner, you would think that a beginner should
start as small and as simple as possible and then work their way up as
their knowledge improves. It seems to me that frameworks are just the
opposite. A beginner needs to start with a bunch of directories they
know nothing about and the easier the framework the more directories
there seems to be.

However this is not to say that this was not a good tip, I can see how
valuable Pylons could be to someone, I'll probably end up with it in the
end, thanks!


Hey Alan

"If you know SQL then you should be able to use the DB API
without any problems. What are the specific issues you are having?"

Thanks for your feedback, tips and your tutorial. I can see how much
documentation the DB API has now. The troubles I was running into were
from my poor understanding of this. Now that I have more documentation I
will be just fine.

"HTH"

It does!, thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Shell scripting

2008-09-17 Thread Patrick
I was just wondering if there was a way to return the results of a
python script to the bash shell? I was thinking about using the output
as an argumen for another shell command. I know that we can use the
shell from within Python via the OS module but I believe this is usually
used to feed input into the program.

Here is a silly pseudo code example:

bash command | some-python-script.py |  some.other-script.sh

thanks in advance-Patrick
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web programming advice

2008-09-19 Thread Patrick

Hi Dorje

I am a beginner like you, I can't provide perfect advice but I have been 
working through this same problem for months.


If you use Python CGI you can get started right away with virtually any 
hosting company but the performance is terrible and the Python 
interpreter installed will be terribly old too.


Python web programming generally forces us into frameworks, which most 
people seem happy to use.


There use to be lots of Python frameworks but there are less now. Django 
is the most popular. Turbogears and Pylons have merged now and they 
would be number 2.


I am in the small minority of people who are don't like frameworks. I am 
really struggling to get going with out one. However there are options 
for us too, I will mention them to you but again most people like 
frameworks just fine.


In the old days all these frameworks did the same basic things 
differently. Eventually the WSGi specification was devised so that there 
would be a common base to work from.


You can actually program directly on the WSGI layer. I am trying to do 
this. You get CGI like control(actually better) with high performance 
but there is not that much documentation and I am personally making slow 
progress. If you happen to be an odd ball like me you might want to take 
the long route too and have a look at this. Once you understand WSGI you 
will likely understand frameworks better too.


Everyone seems to like frameworks but consider this,

According to this article there have been changes to 350K lines of code 
in Django:

http://www.djangoproject.com/weblog/2008/sep/03/1/

I am sure this is an awesomely powerful framework but how the hell does 
anyone understand the magic under the cover with so many lines of code? 
Are you really programming in Python or are you programming in Django now?


Please also watch this youtube episode, a talk by Turbogears Mark Ramm:
http://www.youtube.com/watch?v=fipFKyW2FA4&feature=PlayList&p=D415FAF806EC47A1&index=12

Check out the dependency graph for Django, it gives me chills.

After I learn WSGI I can program without dependencies and I am looking 
forward to it despite the tediousness that I am sure will also come with 
working at this level.


Please also see Werkzeug and Paste. They are tools to help program at 
the WSGI level.


There are many, many people who can offer better guidance then me but if 
you have any further questions please ask, I really want to help-Patrick





According to this article:
http://www.djangoproject.com/weblog/2008/sep/03/1/ over 350K lines of code

dorje tarap wrote:

Hi All,

I would really like to learn about using python for creating a website
from scratch to allow me to learn about web programming and python.

I have zero experience of web programming, and some limited exposure
to python. Can someone recommend a book or resource that will
introduce me to web programming.

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web programming advice

2008-09-19 Thread Patrick

Hi Dorje and Alan

First off, everything that Alan has said is true and I would like to 
re-iterate my lack of qualifications. I depend on people like Alan to 
guide me. Just a couple of days ago I posted an extremely silly question 
about shell programming.


So having said that I think there are two veins of discussion that would 
be helpful to you, One a framework discussion and the other a list of 
terms you need to learn.


I have not used Django for any project but I have read about it and it 
is very popular, however just because everyone else is using does not 
mean you have to. Alan and Ken are right, you don't have to know what's 
under the hood to use a framework but I think the choice of a framework 
is of paramount importance. It appears to me that Django is an 
all-in-one monolithic application. Years ago Zope was the number 1 and 
now it's basically gone. Unless speed and easy of use are of paramount 
importance I suggest that you look at Pylons/Turbogears(unless of course 
you want to join me in the search for the lost city of Atlantis(WSGI 
programing)). This way if you do not like your framework you can take 
much of your code with you to another framework. I don't think this will 
be the case with Django.


You can switch out components with relative ease with Pylons and to a 
lesser degree with Turbogears.


Here are some terms you need to learn. I can help if you need it or you 
might want to search wikipedia for them:

ORM relational mapper, you might look at SQLAlchemy
MVC Model view Controller
Templating engine
WSGI
Url Routing

I am sure I will think of more later


Once your done your App, you then have to host it, you have far fewer 
choices then with PHP. You could try Webfaction or maybe you would like 
to run it on a virtual server, Slice hosting has pretty cheap 
packages($25 ish)



Sorry to make this about me again but in my defense of my last post, I 
really think that you do want to think about long term commitments, it 
takes along time to learn this stuff. I use GTK and I don't care about 
the code it's written in. I am confident that it will be with us in five 
to ten years and I am totally confident that Python will be with us for 
much longer. I have been thinking about learning TCL/Tk recently. It has 
lots of benefits but it also looks like it has been in a steady decline 
for some time. Choosing a language or a framework is in a sense a 
business decision. I don't think that the Python framework world has 
stabilized just yet, I am personally confused about what to do, so 
remember it is the blind leading the blind here but I urge you to 
consider something that decouples well.


-Patrick



Alan Gauld wrote:

"Patrick" <[EMAIL PROTECTED]> wrote


I am in the small minority of people who are don't like frameworks.


There used to be a small minority of people who didn't like compiled
or other high level languages. But they gradually died out... There
was even a very small community who didn't like assembler, preferring
to enter binary or hexcodes directly, but they died out very quickly!


really struggling to get going without one.


Yep, that's why other folks like them! :-)

You can actually program directly on the WSGI layer. I am trying to 
do this. You get CGI like control(actually better) with high performance


Just as you can program a Windows GUI using the Win32 API.
Or use XLib on X windows. (X in very interesting because it has
many layers of abstraction designed right in, from XLib to Xt to
XView/Motif/GTK etc) But its all incredibly painful!

According to this article there have been changes to 350K lines of 
code in Django:

http://www.djangoproject.com/weblog/2008/sep/03/1/

I am sure this is an awesomely powerful framework but how the hell 
does anyone understand the magic under the cover with so many lines 
of code?


Only the developers do. There are hundreds of thousands of lines in a
GUI framework too but nobody feels the need to read them all before
using wxWindows or Tcl/Tk or GTK...

Are you really programming in Python or are you programming in Django 
now?


You are programming in Python using Django.
Similarly when you import the os module you are programming in Python
using the os module. If you look at the source for os and then drill down
to look at the Unix C libraries utilised you will find many thousands of
lines of code there too, before you ultimately call the OS system calls.
If you then drill into the system call code (which you can do in Linux or
Darwin) you will find that they eventually call BIOS routines written in
assembler. But very few programmers bother reading the assembler
code for the BIOS routine (interrupt 0x13 from memory?) that writes to
disk before considering whether they should use file.writelines() in
Python...

The whole of software engineering is built up on layers of software
provided by others. 'Framework' is just a f

Re: [Tutor] Web programming advice

2008-09-19 Thread Patrick
Sorry to create another post and fill up everyones mailboxes but I 
forgot something important...


In terms of searching for documentation I believe you should look to the 
framework of your choice. There is not that much non-cgi related 
programming documentation out there-patrick


Alan Gauld wrote:

"Patrick" <[EMAIL PROTECTED]> wrote


I am in the small minority of people who are don't like frameworks.


There used to be a small minority of people who didn't like compiled
or other high level languages. But they gradually died out... There
was even a very small community who didn't like assembler, preferring
to enter binary or hexcodes directly, but they died out very quickly!


really struggling to get going without one.


Yep, that's why other folks like them! :-)

You can actually program directly on the WSGI layer. I am trying to 
do this. You get CGI like control(actually better) with high performance


Just as you can program a Windows GUI using the Win32 API.
Or use XLib on X windows. (X in very interesting because it has
many layers of abstraction designed right in, from XLib to Xt to
XView/Motif/GTK etc) But its all incredibly painful!

According to this article there have been changes to 350K lines of 
code in Django:

http://www.djangoproject.com/weblog/2008/sep/03/1/

I am sure this is an awesomely powerful framework but how the hell 
does anyone understand the magic under the cover with so many lines 
of code?


Only the developers do. There are hundreds of thousands of lines in a
GUI framework too but nobody feels the need to read them all before
using wxWindows or Tcl/Tk or GTK...

Are you really programming in Python or are you programming in Django 
now?


You are programming in Python using Django.
Similarly when you import the os module you are programming in Python
using the os module. If you look at the source for os and then drill down
to look at the Unix C libraries utilised you will find many thousands of
lines of code there too, before you ultimately call the OS system calls.
If you then drill into the system call code (which you can do in Linux or
Darwin) you will find that they eventually call BIOS routines written in
assembler. But very few programmers bother reading the assembler
code for the BIOS routine (interrupt 0x13 from memory?) that writes to
disk before considering whether they should use file.writelines() in
Python...

The whole of software engineering is built up on layers of software
provided by others. 'Framework' is just a fancy name for a particular
type of layer. If it makes the job easier and delivers acceptable
performance use it. If not drop down a layer.

Sometimes programming at the lower levels can be useful for learning,
sometimes it can be a fun challenge in its own right. But if you need
to get a job done go with the highest level software support you can 
find!

Thats why we are using Python and not C, right?




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] parallel port help

2009-02-06 Thread Patrick

Hi Everyone

I would like to write a Python program to control the data lines of a 
parallel port.


PyParallel seems buggy, even the install script has one and it has 
practically no documentation.


Portio also failed to install for me.

Is there any other library you could point me too, or do you have any 
other advice? Is there someway to control individual data lines from bash?



Thanks in advance-Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Non-escaped utf-8 rendering in the interactive shell under XP?

2004-12-13 Thread Patrick Hall
Hi folks,

Being a Linux guy, I don't know my way around Windows software too
well. I've been trying to help some friends learn a bit of Python, and
they use OSX and XP.

OSX is close enough to Linux that I've not run into many barriers, but
I'm having a specific problem with the XP users:

Is there an IDE out there that supports Unicode (utf-8) text? 

I've set sitecustomize.py to 'utf-8', such that
sys.getdefaultencoding() will return 'utf-8', and everything seems to
be working ok interms of reading, writing, and processing data in
utf-8. The problem is that the text itself is escaped in the
interactive shell, rather than being rendered. It's not a font thing,
since if they write out the data to a file and open it in a browser,
the text is readable.

The Gnome terminal under Linux seems to do this fine once I've made
that change in sitecustomize.py, and OSX seems to behave similarly.

I've suggested my friends try SciTE, Idle, and Activestate's
PythonWin, and as far as I can tell none of these IDEs solve the
problem.

The people I'm trying aren't going to be interested in wading into
something like any flavor of Emacs or vim. After all, they want to
learn Python because it's friendly, and those editors are great, but
they're not friendly.

Am I missing any options or misunderstanding any of these IDEs? 

Thanks kindly,
Patrick
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin

Giorgio wrote:

i am looking for more informations about encoding in python:

i've read that Amazon SimpleDB accepts every string encoded in UTF-8. 
How can I encode a string? And, what's the default string encoding in 
python?


I think the safest way is to use unicode strings in your application and 
convert them to byte strings if needed, using the encode and decode methods.





the other question is about mysql DB: if i have a mysql field latin1 and 
extract his content in a python script, how can I handle it?


if you have a byte string s encoded in 'latin1' you can simply call:

s.decode('latin1')

to get the unicode string.



thankyou

Giorgio


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


Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin



Mmm ok. So all strings in the app are unicode by default?

Depends on your python version. If you use python 2.x, you have to use a 
u before the string:


s = u'Hallo World'

Do you know if there is a function/method i can use to check encoding of 
a string?


AFAIK such a function doesn't exist. Python3 solves this by using 
unicode strings by default.


Patrick, ok. I should check if it's possible to save unicode strings in 
the DB.


It is more an issue of your database adapter, than of your database.



Do you think i'd better set my db to utf8? I don't need latin1, it's 
just the default value.


I think the encoding of the db doesn't matter much in this case, but I 
would prefer utf-8 over latin-1. If you get an utf-8 encoded raw byte 
string you call .decode('utf-8'). In case of an latin-1 encoded string 
you call .decode('latin1')



Thankyou

Giorgio

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


Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin

Giorgio wrote:


Depends on your python version. If you use python 2.x, you have to
use a u before the string:

s = u'Hallo World'


Ok. So, let's go back to my first question: 


s = u'Hallo World' is unicode in python 2.x -> ok
s = 'Hallo World' how is encoded?


I am not 100% sure, but I think it depends on the encoding of your 
source file or the coding you specify. See PEP 263

http://www.python.org/dev/peps/pep-0263/

Well, the problem comes,  i.e when i'm getting a string from an HTML 
form with POST. I don't and can't know the encoding, right? It depends 
on browser.


Right, but you can do something about it. Tell the browser, which 
encoding you are going to accept:



...


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


[Tutor] Resetting the namespace

2010-03-08 Thread Patrick Sabin
I found this piece of code, which completely puzzles me, in the pdb 
module of the trunk:


class Pdb(bdb.Bdb, cmd.Cmd):
...
def _runscript(self, filename):
# The script has to run in __main__ namespace (or imports from
# __main__ will break).
#
# So we clear up the __main__ and set several special variables
# (this gets rid of pdb's globals and cleans old variables on
# restarts).
import __main__
__main__.__dict__.clear()
__main__.__dict__.update({"__name__": "__main__",
  "__file__": filename,
  "__builtins__": __builtins__,
 })

The intention of this code is to reset the namespace, before executing a 
script.


When I try to do something similar, i.e. __main__.__dict__.clear(), I 
loose the __builtins__ variable in the namespace, e.g.:


>>> import __main__
>>> print __builtins__

>>> __main__.__dict__.clear()
>>> print __builtins__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name '__builtins__' is not defined

But for some reason the code mentioned above actually works in the case 
of pdb. Any ideas why?


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


Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Patrick Sabin

   ipAddress = "123.123.123.123"
   emails = ipAddress.GetEmailAddresses()


Not exactly sure, what you want, but maybe something like this?

class mystr(str):
def GetEmailAddresses(self):
return [str(self)]

ipAddress = mystr("123.123.123.123")
emails = ipAddress.GetEmailAddresses()

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


Re: [Tutor] Sequences of letter

2010-04-11 Thread Patrick Sabin

So far this is what I have:
letras = 
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"]

letra1 = 0
letra2 = 0
letra3 = 0
for i in letras:
for j in letras:
for k in letras:
print letras[letra1]+letras[letra2]+letras[letra3]
letra3=letra3+1
letra2=letra2+1
letra1=letra1+1


It goes all the way to aaz and then it gives me this error
Traceback (most recent call last):
 File "/home/administrador/programacion/python/letras2.py", line 8, in 


print letras[letra1]+letras[letra2]+letras[letra3]
IndexError: list index out of range


You should consider resetting the letra-variables before each loop (not 
before every loop).


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


Re: [Tutor] pygtk

2009-09-08 Thread Patrick Sabin

The official docs

http://www.pygtk.org/pygtk2tutorial/index.html
http://library.gnome.org/devel/pygtk/stable/

worked for me.

- Patrick

Ajith Gopinath schrieb:
I will appreciate , if somebody guides me to a proper doc. on pygtk 
for 2.5/2.6. I am currently unable to find a good doc for the same :o(


Thanks and regards
~|| a j i t ||


___
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] include remote module

2009-09-12 Thread Patrick Sabin

Maybe something like this helps you to solve your problem:

# get code via http, etc.
code = """
def blah():
print 'blah'

print 'hello'
blah()
"""

compiled_code = compile(code, 'filename', 'exec')
exec(compiled_code)

This way you could execute some code from a web client, but the client 
would be able to execute any code, he could even delete your hard drive.


- Patrick

Patrick schrieb:

Hi Wayne

Thanks for your help. I was thinking of the latter but now that I think
of it, once you import a module it won't help to modify that module on
the fly later anyways, right?  I would need to re-import it. Sounds like
reading it via http would be simpler.

Thanks again-Patrick

Wayne wrote:

On Sat, Sep 12, 2009 at 7:55 AM, Patrick mailto:optoma...@rogers.com>> wrote:

Strange question.

Is it possible to include a module that is on another computer?

I have been day-dreaming about a project that would allow web code to
drive a desktop App.


I know of one way, using sshfs, which allows you to mount an ssh
location as a directory on your computer. Then it would effectively be
a local filesystem. I don't know if there's something like that on
Windows.

Of course, what do you mean when you say "web code to drive a desktop
app"? Do you mean you want to host some code that others can connect
to that will change? Or do you mean you want people to connect to your
server and it will run an app on your desktop?

For the former it's not really necessary to include the mod on another
computer. Just use the http libraries and download the file when the
script runs. Then import it.

HTH,
Wayne


___
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] Sorting 2-d data

2009-09-13 Thread Patrick Sabin
 > But for sorting the list with the first element as key, I tried it 
using
just mylist.sort() without the lambda, and its working also. Then why 
use the lambda?




There is a little difference between those two variations.
Example:

>>> sorted([[1,2],[1,3],[1,1]])
[[1, 1], [1, 2], [1, 3]]
>>> sorted([[1,2],[1,3],[1,1]], key=lambda x:x[0])
[[1, 2], [1, 3], [1, 1]]

For sorting it is necessary to compare items. So for example [1,1] is 
compared to [1,2]


As you see:
>>> [1,1] < [1,2]
True

If you apply the lambda things change:
>>> (lambda x: x[0])([1,1])<(lambda x:x[0])([1,2])
False
>>> (lambda x: x[0])([1,1])==(lambda x:x[0])([1,2])
True

This is because now only the first item of the list is compared.

- Patrick


___
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] Image manipluation (On-the-fly thumbnail creation)

2009-09-15 Thread Patrick Sabin

dan06 wrote:

I've recently delved into python, about a week or so ago; I'm trying to
figure out how to create on-the-fly thumbnails. Are there python standard
library modules I could/should use or should I use external libraries like:
GD, Gimp, or ImageMagick?  


When I needed thumbnails of my images, I created them using ImageMagick. 
 ImageMagick is a very nice tool for editing images and since it is 
called from the command line it is easy to invoke it from a programming 
language. There are python-bindings for it, but I think they are not 
very actively maintained and so I wouldn't use them.


Using PIL is another option and maybe more pythonic, but if you are 
familiar with ImageMagick it might be a good alternative.


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


Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Patrick Sabin

Ansuman Dash schrieb:


Hello Everybody,

In Python scripting, how can I execute a command (which can be run from 
spcific directory) and then retrieve the result (after executing the 
command it give the command is executed successfull or not), so that I 
can validate it.


Thanks,
AD




import os
import subprocess

os.chdir('/your/directory')
p = subprocess.Popen("ls -l", shell=True, stdout=subprocess.PIPE)
out = p.stdout.read()
print out

- Patrick

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


Re: [Tutor] Using the time module to extract a semi-random number

2009-09-17 Thread Patrick Sabin

Laurii wrote:

Hello all,

I am currently reading through the Tutorial for Non-Programers by Josh 
Cogliati.  I have had great success until now.


The exercise to modify a number guessing program from a fixed number 
"number = 78" to using the time module and use the seconds at the time 
the program is used to be the number. (i.e. if the clock on your 
computer says 7:35:25 then it would take the 25 and place it in "number".




You can either use:

import time
number = int(time.strftime("%S"))

or use real pseudo-random numbers:

import random
number = random.randint(0,59)

The latter looks clearer to me.

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


Re: [Tutor] real world decorators

2009-09-21 Thread Patrick Sabin

John wrote:

Hi,

I think I understand what decorators are and how they work.  Maybe it's just 
me but I don't know where I'd use them in my real world programming.  I see 
how they work with profile or coverage but does anyone have real world uses.  


@classmethod, @staticmethod, @property, @abstractclass, 
@abstractproperty are in my opinion the most import. Some toolkits use 
them too.



I mostly create wxPython apps and don't see where they might apply.



The wx toolkit is designed to work with C++ and wxPython is just a 
language binding for it. As far as I know C++ doesn't support Decorators 
or something similar like it. So there won't be many uses for decorators 
in wx apps.



I know the tutors will enlighten me!


Some ideas for decorators, if you want to play around with them:

@fireandforget
Make a function call in another thread, so you can return
immediately - without returning result. This could be for
example useful to send an email without needing to wait, until
it is sent.
@cache
Cache the results of a function in a dictionary. If the function
is called look up the value of the cache first. This only works
with side-effect free functions of course.
@timeout
Check if the execution time of a function exceeds a timeout
limit. If so raise an exception.
@ignoreexceptions

In my opinion, you should avoid using decorators in productive code, if 
you don't have a good reason to do otherwise. Every decorator adds some 
sort of "magic" to your program and using too much "magic" will make it 
difficult to maintain.


- Patrick

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


Re: [Tutor] code improvement

2009-09-29 Thread Patrick Sabin

You could invert your if-expressions, e.g. instead of

if query_company_name:
...

you could write

if not query_company_name:
return adresses, company
...

This way you could save some indentation.

If you want to get rid of the for loops, you could look at list 
comprehensions, e.g.


cmps = [ressource.get_resource(item, soft=True) for item in companies]

- Patrick

Norman Khine wrote:

On Thu, Sep 24, 2009 at 10:25 PM, Kent Johnson  wrote:

On Thu, Sep 24, 2009 at 2:12 PM, Norman Khine  wrote:

Hello,
I have this function in my class:

http://paste.lisp.org/display/87659

Is there a better method to write the last bit of the code.

Better in what way? What are these things? What is resource? Some
context would be helpful, I seem to have misplaced my mindreader hat.


Apologies for not being clear. I was thinking more  that I may have
one the too many 'for' loops at the end of the code.

Here is a new version with more details.

http://paste.lisp.org/display/87659#1

Thanks

Kent


___
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] help with alternate execution

2009-10-02 Thread Patrick Sabin

 wrobl...@cmich.edu wrote:

Thank you for the reply.. I tried putting the print repr(n)
before I defined 'n' with raw_input. My script looks like
this--


def divisible(n):
   if n%3 == 0:
   print n, "is divisible by 3"
   else:
   print n, "is not divisible by 3"
n= raw_input("enter a number= ")
print repr(n)

print divisible(n)



I don't understand what the problem is


The problem is raw_input gives you a string. So in your example n is a 
string and when it comes to n%3 python tries to format your string, but 
since you haven't any formating symbols in it, it fails.


To fix your program, convert the n to int:

divisible(int(n))

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


[Tutor] Moving a Shelf Between Linux and Mac OS X

2009-10-24 Thread Patrick Kenny
Greetings,

I recently started learning Python and I have written a script that uses
a shelf on Mac OS X using Python 2.6.  I recently attempted to move the
directory over to my Linux system, which also has Python 2.6 installed,
and run the script there.

The script works fine, but the shelf does not load.  Instead, it appears
that a new shelf is created.  On the Mac, the shelf file is saved as
class-shelve.db, but after running the script on Linux, a new file,
class-shelve (without a .db suffix) is created.

I tried simply deleting class-shelve and renaming class-shelve.db as
class-shelve, but when I run the script I get this error:

Traceback (most recent call last):
  File "card.py", line 232, in 
DisplayInventory(scope)
  File "card.py", line 65, in DisplayInventory
db = shelve.open('class-shelve')
  File "/usr/lib64/python2.6/shelve.py", line 234, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
  File "/usr/lib64/python2.6/shelve.py", line 218, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback)
  File "/usr/lib64/python2.6/anydbm.py", line 82, in open
mod = __import__(result)
ImportError: No module named bsddb185

Are shelves portable between different OSs?  I would like to make the
data created on the shelf on the Mac also accessible on Linux; is there
an easy way to do this?


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


Re: [Tutor] class Knights vs class Knights(object)

2009-11-07 Thread Patrick Sabin

Wayne Werner wrote:

and my question is what is the difference between the two? Is there a 
difference other than one is an object the other is an instance? I 
googled "python object vs. instance" and didn't find anything terribly 
useful.


Yes there is a difference. One class inherits from object, the other 
doesn't. You may want to try to check this, e.g.:


issubclass(Knight, object)

So the first keyword you may want to google for is inheritance.

The second keyword is old/new-style classes.

Python 2 changed the way how classes work, but to be backward compatible 
the old mechanism still remained. If you want new style classes inherit

from object.

If you want to understand the details you may want to look up what 
metaclasses - your third keyword - are, old-style classes have the 
metaclass classobj, new-style classes type. You can check this using the 
builtin type-function.


Beware that this is python 2 stuff. In python 3 class X: and class 
X(object): are the same.


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


Re: [Tutor] Unexpected iterator

2009-11-12 Thread Patrick Sabin

Jeff R. Allen wrote:


a, b = 0

Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not iterable

I understand why it doesn't work, but I don't understand the wording
of the exception. Could someone explain how I accidentally introduced
iteration into the picture with my syntax? I have a feeling there's an
interesting lesson hidden in this example...


To upack your variables a and b you need an iterable object on the right 
side, which returns you exactly 2 variables, e.g you could also write


a, b = range(2)

or create your own class

class X:
def __iter__(self):
yield 0
        yield 0

a,b = X()

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


Re: [Tutor] simple list query

2005-01-02 Thread Patrick Hall
Hi Dave,

> I have a list consisting of about 250 items, I need to know if a
> particular item is in the list. I know this is better suited to  a
> dictionary but thats not the way it ended up ;-)

> I could do a for loop to scan the list & compare each one, but I have a
> suspission that there is a better way ?

Indeed there is: just use the built-in "in":

>>> li = ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c']
>>> 'a' in li
True
>>> 'z' in li
False

That's a small example, but it will work equally well with a long
list. For instance, we can check to see if the words "Ahab", "whale",
and "pizza" are in the text of "Moby Dick" (I have the text in a file
called "moby.txt".)

>>> moby = open('moby.txt').read() # Moby Dick, the whole thing!
>>> mobywords = moby.split() # now mobywords has all the words in the text
>>> 'Ahab' in mobywords
True
>>> 'whale' in mobywords
True
>>> 'pizza' in mobywords
False

These results are unsurprising. 8^)

A list of 250 words is no problem -- "Moby Dick" has a couple hundred thousand:

>>> len(mobywords)
214112

I'm not sure I understand why you think a dictionary would be better
in this case, a list seems fine to me.

Best,
Pat
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to create a key-value pairs with alternative elements in a list ... please help.

2005-01-16 Thread Patrick Hall
Hi!

>>> while True:
> ... try:
> ... d[slice0.next()] = slice1.next()
> ... except: StopIteration
> ... break
> ...  

###

while True:
 try:
  d[s0.next()] = s1.next()
 except StopIteration: # wherein we point out a wayward colon
  break

###

Took me a while to figure out why I kept getting error messages about "break":

try:
 something()
except YourExceptionHere:
 something_else()

Misplaced colon. Why those sneaky little...

Cheers,
Pat
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Patrick Hall
> Beware! Overcome the temptation!
> Try this: http://kodos.sourceforge.net/

While I have no problem personally with Perl or PHP, I'll second the
recommendation for kodos -- it's very useful for learning to use
regexes in Python.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Small GUI toolkit and executable creators

2005-02-04 Thread Patrick Kirk
Hi all,
I'm writing an application that will distributed by download and want it 
to be as small as possible.  The target platform is Windows.

For the GUI toolkit, I am looking at wxPython and tkinter.  For a small 
application with only 4 working forms, which can be expected to produce 
the smaller programs?

To create executables, I'm looking at using
py2exe - http://starship.python.net/crew/theller/py2exe/
or
Installer - http://davidf.sjsoft.com/mirrors/mcmillan-inc/install1.html
Has anyone any comments on which produces smaller executables and and if 
either is qualitively better than the other.

Thanks in advance.
Patrick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Small GUI toolkit and executable creators

2005-02-04 Thread Patrick Kirk
That looks fine size wise. Thanks.
Ismael Garrido wrote:
Patrick Kirk wrote:
Hi all,
I'm writing an application that will distributed by download and want 
it to be as small as possible.  The target platform is Windows. 

Use UPX, 7Z and NSIS. ;-) (and in that order, too :-P)
That's with Py2exe, never tryed the other one.
I made a program with Tkinter and managed to get it all together in 
1.8Mb, 8kb of source :-S

Gretz
Ismael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello and newbie question about "self"

2008-02-03 Thread Patrick Lists
Hi Alan,

Alan Gauld wrote:
> "Patrick" <[EMAIL PROTECTED]> wrote 
> 
>> Can anyone please point me to a document that explains "self" in
>> layman's terms. 
> 
> Try the OOP topic inmy tutorial...

Thanks will have a look.

>> Or lacking such a doc throw in a much appreciated
>> layman's explanation what "self" is and when/where to use it? 
> 
> Others have given code samples but a conceptuial explanation 
> is that 
> a) self is only used in OO programming within metjhods of a class.

Now that really helps. I was wondering about that and this answers it.

> b) self refers to the actual instance of the object receiving the 
> message with caused the method to be invoked.

This and reading chapter 23 in the book makes things much clearer now. 
Thanks!

> Thus if we have a class C with a method m and 3 instances 
> a,b and z then when we invoke a.m() self will refer to a and 
> when we invoke b.m() self will refer to b. This means that the 
> innards of the method can use self to access the instance 
> specific data for that invocation.

Even more clear now :)

> If you have used C++ at all you might recognise it as the 
> same as 'this' in C++ except that in Python you must explicitly 
> specify it whereas C++ creates 'this' magically behind the scenes.

Last time I used C++ was (iirc) in 1987 with a Borland product. I recall 
"this" and remember I got stuck on it then too.

> See my tutorial for more on this under the heading 
> "Using classes".

Will do. Thanks for the pointer.

> If you haven't started writing classes yet, you can safely ignore 
> it for now!

I probably won't need to start writing classes but I really want to 
finish the book before I start coding something. I have a small script I 
did in (horrible) bash and look forward to try to implement it in (less 
horrible) Python.

Thanks for your help.

Regards,
Patrick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] removal

2005-10-22 Thread Patrick Nagle
please remove me from your tutor mailing list.

Cheers

--
Patrick J. Nagle
_
Pocket Rocket FX
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-06 Thread Patrick Wheeler
>data = [ ]>for i in xrange(1,101):> data = "" %i  _n, f %i_v))

The function locals() will return a dictionary of variables in the
current scope.  This can then be used to reference variables by
name.
x=1
xname = 'x'
print locals()['x']
print locals()[xname]
This prints:
1
1

or for your example.
data = [ ]
for i in xrange(1,101):
    data = "">

Hope this helps.

pjw

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter ... deactivating a Text window when a radiobutton is chosen

2006-12-14 Thread Patrick Lorenz
I'd appreciate some help.  I am just learning Tkinter, and want to 
deactivate a Text window when a certain radiobutton is selected.  I 
cannot figure it out.  I believe I need to reset the state option of the 
Text window to be 'disabled', but I'm not able to find  a way to do it, 
even though I have tried different ways, including using the radiobutton 
command option, etc.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: turbo gears

2008-06-05 Thread Patrick Mullen
Yeah, I like turbogears as well.  I was using cherrypy before turbogears
borrowed it, and have a hard time remembering that turbogears has more than
just cherrypy (pretty much just use cherrypy still, even though it's called
tg).  It's a bit weird with TG2 now moving to pylons - which is not
cherrypy.  I don't know how I feel about that lol!

But no, you won't be wasting your time.  Many of the python frameworks do
share similar concepts, even if they come at it from different
perspectives.  And they are all better than plain php, although many of my
php developer friends would argue that whatever php framework they use is
just as good :)  Turbogears will be around for a long while, even if it
seems django is winning at the moment.  There are many developers and many
people using it, so it has a long life ahead.  Even if it didn't get
expanded though, what's there currently is plenty to support any web
application you would want to make.

In my experience php bugs are harder to spot than python bugs.  Generally,
most python bugs will cause an error while most php bugs wont.  But this is
a python developers perspective of php and not the other way around, soyour
milage may vary.  But be on the lookout for this anyway.  You cant just let
an error pass by and test a different part of the page.  It's a bit
different development style than php.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the "@" operator mean?

2008-12-16 Thread Patrick Mullen
On Mon, Dec 15, 2008 at 5:03 PM, Alan Gauld  wrote:
>
> "Marc Tompkins"  wrote
>
>> If you're just starting out in Python, decorators can be hard to get
>> your head around...
>
> I've been using Python for oover 10 years and still find decorators
> hard to get my head around! :-)
>
> I confess I'm not a fan, they go against the Python spirit of
> explicit is best in my opinion. If I'm calling a function I like to
> know I'm calling a function... I know they make the code look
> pretty but IMHO they are a pain to debug and I'm never totally
> convinced I've got it exactly right.

I thought this way for a while, but I "get" them now.  Mostly I use
them as a shortcut to setting some variables on a function, which
could later be used for introspection.  For instance, a dead simple
test framework I wrote uses decorators like this:

@test("Just load something",removefiles=["sprite1.txt"],teardown=sprite_cleanup)
def load_sprite():
f = open("sprite1.txt","w")
f.write("""texture metatex1.png
horizontal 2\nvertical 2\nlength 4\nloops 3""")
f.close()

The decorator signifies to the testing framework that this function should
be run, the file sprite1.txt should be removed after running the test, and
the function sprite_cleanup should be run as well.  This could have been
done in other ways, but it is a lot more clear with a decorator.
"Hey testing framework, here is how you should run this function"

The actual code for the decorator is not complex either:
def test(t,removefiles=[],teardown=None):
def dec(f):
f.a_test = True
f.test_desc = t
f.removefiles = removefiles
f.teardown = teardown
return f
return dec

The function in a function is a bit headache inducing, I'll grant that.  But the
dec function just sets some variables on the function.  This could be done
in the old way:

def test(f,t,removefiles=[],teardown=None):
f.a_test = True
f.test_desc = t

With the functions decorated like this:
def test_sprites:
[code]
test(test_sprites,"Just load
something",removefiles=["sprite1.txt"],teardown=sprite_cleanup)

For me though, it is MUCH better to have this information before the
function instead of after.


Another place I am using them is in an interpreter class.  The class
has various methods
tied to different commands that it understands.  I also have a gui
where commands
can be chosen, according to the category of the command.  The
decorator is used to
add some information that the gui can use about the nature of the
command, and which
category it falls under.

I don't used any advanced features of decorators at all, they just
make the code a little
bit more clear and allow me to do a bit more introspection of
functions for various purposes.
I don't use them often, but I do like them.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] scraping and saving in file

2010-12-30 Thread Patrick Sabin

On 2010-12-29 10:54, Tommy Kaas wrote:

It works fine but besides # I also get spaces between the columns in the
text file. How do I avoid that?


You could use the new print-function and the sep keyword argument, e.g.:

from __future__ import print_function

f = open("filename", "w")
print("1", "2", "3", file=f, sep="")

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


Re: [Tutor] GUI + python program

2011-02-14 Thread Patrick Sabin

You have a lot of options:

GUI: Any major gui toolkit will do the job. It's probobly easiest to 
stick with tkinter.


HTML Template: Use a template language, e.g. mako or django templates
Pdf Templates: Reportlab is an option.

File Access: Of course you could just open a file and write to it, but 
it probably gets messy. I would recommend using a database. Sqlite is 
maybe a good choice, or sqlalchemy.


- Patrick

On 2011-02-14 20:55, Mitch Seymour wrote:

Hello,

I am trying to design a program and GUI that will allow the user to
select from a series of options and, depending on which options are
selected in the GUI, information will then be placed in a html or pdf
template.

Here's an example.

Option A
Option B
Option C

If Option A, insert _ into the template.
If Option B, insert _ into the template.
If Option C, insert _ into the template.

The reason I used __ is because the user needs to be able to edit,
from the GUI, which information is associated with each option, and,
subsequently, which information will be placed into the template.

However, I am very new to python and I don't how to do this. A friend
suggested that I create a python file that would store the user defined
information, which would be read by the program before the information
is placed into the template. So the user could select the options from
the GUI, edit the associated information from a preferences tab, and
then initiate the process of placing the info into the templates.

My question is, how would you do this and, if I do create a file to
store the information, could you please give me some examples of code to
get me started?

Thanks so much!




___
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] Need help with arrays

2011-05-04 Thread Patrick P .

Hello,

I hope this is the right way to ask my question, if not, sorry to bother you. 
Maybe you can tell me who to ask.
Ok so here is my code

import numpy as np

nH = 2.2
nL = 1.7
welle = 0.5 
wurzel = (8.85*10**(-12) * 12.57*10**(-7))**0.5 * 10**6 
w = np.arange(0.50, 1.50, 0.01)

inc = 25
inc1 = np.arcsin((1/nH))*np.sin(inc)
inc2 = np.arcsin((nH/nL)*np.sin(inc1))

del0 = 2*np.pi*welle*np.cos(inc)/w
del1 = 2*np.pi*nH*(welle/nH)*np.cos(inc)/w
del2 = 2*np.pi*nL*(welle/nL)*np.cos(inc1)/w

nu1 = wurzel*nH*np.cos(inc1) 
nu2 = wurzel*nL*np.cos(inc2)

# Matrix 1

m111 = np.cos(del1)
m121 = 1j*np.sin(del1)/nu1
m211 = 1j*nu1*np.sin(del1)
m221 = np.cos(del1)
A = np.array([[m111,m121], [m211,m221]])

# Matrix 2

m112 = np.cos(del2)
m122 = 1j*np.sin(del2)/nu2
m212 = 1j*nu2*np.sin(del2)
m222 = np.cos(del2)
B = np.array([[m112,m122], [m212,m222]])

print(np.dot(A,B))


Traceback (most recent call last):
  File "C:/Python26/helpfiletest.py", line 36, in 
print(np.dot(A,B))
ValueError: objects are not aligned
-
I get it why theres and error message, because it's trying to multiply a 
2x2x100 array with another 2x2x100 array and doesn't know how to do that.
What I actually want is 100 2x2 arrays and then mutliply them individually.
Can anyone help me with that?

Thanks a lot! Best,

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


Re: [Tutor] Nodes and Queues?

2011-05-11 Thread Patrick Sabin
A queue is a data structure, which keeps track of multiple objects. You 
can add data to a queue or you can remove it. When you remove an object 
from a queue you get the element which you have added first. Therefore, 
it is also called FIFO (First In First Out). A basic implementation 
could look like this:


class Queue:
def __init__(self):
self.items = []

def add(self, obj):
self.items.append(obj)

def remove(self):
self.items.pop(0)

Nodes are used in multiple contexts, but usually refer to objects which 
have child objects.


--
Patrick

On 2011-05-11 13:44, Clara Mintz wrote:


Hi all
I am sorry I am a beginner at python and I was reading my book and I came 
across the terms Nodes and Queue. I am sorry but I don't quite understand how 
they work. Is there anyone who could possibly explain them in simple terms? 
Thank you so much.
Sincerely,
Clara


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


Re: [Tutor] Python program with multiple answers

2011-05-11 Thread Patrick Sabin

 * Create a list.
 * Each time, the user gets an answer add it to the list
 * At the end of the program: sort the list and print each element of it

- Patrick

On 2011-05-11 12:49, Johnson Tran wrote:

Hi Guys,

I've been working on a Python program where I create an 8 ball that will allow 
you to ask questions and will reply back with 20 possible answers. It will be 
continuous until the user says quit. My program works fine although I am trying 
to add something more to it, where when the user quits, it will present all the 
answers that the user got again and display them in alphabetical order...if 
anyone could point me in the right direction it'd be really helpful...my 
program so far is : (which works fine with no errros)



import random
dice = ("Without a doubt", "It is certain", "It is decidedly so","Yes", "For Sure", "No", "Dont count on it", "Try asking again","Reply hazy, try again", "Confucious says 'No'", 
"Better not tell you now","Cannot predict now","Concentrate and ask again","My reply is no","Outlook not so good","Very doubtful","Outlook is good","Most likely","As I see it, yes","I 
do not understand the question")
while True:
choice = raw_input("Type 'ask' to ask a question. Type 'quit' to 
quit.\n")
if choice == "ask":
raw_input("Please enter your question:\n")
roll = random.randint(0, 10)
print dice[roll]
raw_input()
elif choice == "quit":
True = 0
raw_input()
else:
print "Error -- Try again\n"





Thanks,

JT

___
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] Installing Modules

2012-01-18 Thread Downey, Patrick
Hello,

I'll start by saying that I have a math/stats background, not a computer
science one. I've found lots of great material to help with Python
programming, but have had a much harder time getting my head around setup
issues, like installing modules.

I'm currently running Python version 2.7 through IDLE on a Windows machine.
I'm trying to use numpy and scipy. I downloaded both modules from the scipy
website and unzipped the files into:
C:\Python27\Lib\site-packages

I try to load them using this at the beginning of my program.
from numpy import *
from scipy import *

And I get this error:
Traceback (most recent call last):
  File "D:/Documents and Settings/pdowney/My Documents/Actual
Projects/Foreclosures/Python/Program (1-18-12).py", line 3, in 
from scipy import *
ImportError: No module named scipy

Numpy loads just fine. Both are in the same folder. That is, there's a file
called setup.py in the folder:
C:\Python27\Lib\site-packages\numpy

And also in the folder:
C:\Python27\Lib\site-packages\scipy

I don't understand what is being done differently between the two packages.
According to Chapter 6 of the Python documentation, "When a module named
spam is imported, the interpreter searches for a file named spam.py in the
directory containing the input script and then in the list of directories
specified by the environment variable PYTHONPATH." Unfortunately, I haven't
figured out how to look at PYTHONPATH, so I don't know where it's looking.
>>> print PYTHONPATH
Traceback (most recent call last):
  File "", line 1, in 
print PYTHONPATH
NameError: name 'PYTHONPATH' is not defined

Importantly, there is no file scipy.py in the scipy folder, as the
documentation suggests there should be, but there's also no numpy.py in the
numpy folder and that module loads successfully. Clearly I'm missing
something in the setup of these modules. Any guidance would be greatly
appreciated.

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


Re: [Tutor] (no subject)

2012-02-08 Thread Patrick Dempster
On 07/02/2012 19:07, Hugo Arts wrote:
> On Tue, Feb 7, 2012 at 7:50 PM, Debashish Saha  wrote:
>> for i in range(1, 8):
>>print(i)
>>if i==3:
>>break
>> else:
>>print('The for loop is over')
>>
>>
>>  Output:
>> 1
>> 2
>> 3
>>
>> Question:but after breaking the for loop why the else command could not work?
>>
> because the else statement was designed to be that way:
>
> http://docs.python.org/reference/compound_stmts.html#for
>
> quoting the relevant part:
>
> "When the items are exhausted (which is immediately when the sequence
> is empty), the suite in the else clause, if present, is executed, and
> the loop terminates.
>
> A break statement executed in the first suite terminates the loop
> without executing the else clause’s suite."
>
> in short, the else clause only executes if you do *not* break out of the loop.

I might be missing something but I can't see a reason for the "else:"
clause attached to the "for" statement, could anyone provide an example
where or why someone might use the "else:" clause with the for loop?

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


Re: [Tutor] responding to command line

2015-11-25 Thread Patrick Hess
richard kappler wrote:
> and I want the script to detect that password request and provide the
> password (Same for all 500 + machines, so no issue there).

My recommendation would be to take a look at Expect[1].

Yes, I know, it's not Python, but using a tool specifically
tailored to handle this kind of task will make life so much
easier that it even justifies the use of Tcl. ;-)

Patrick

[1] http://expect.sourceforge.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] responding to command line

2015-11-25 Thread Patrick Hess
Alan Gauld wrote:
> But there is a python wrapoper round expect - pexpect - that
> means you don't need to learn Tcl ;)
> 
> https://github.com/pexpect/pexpect
 
Interesting, thanks. And better yet, it's not just a wrapper
around Expect: "Pexpect is in the spirit of Don Libes' Expect,
but Pexpect is pure Python." So you don't even have to install
anything Tcl. :-)

On the downside, Windows support seems to be quite limited at
this point. However, if that's not of any concern to Richard,
Pexpect is probably his best option. This example right here
looks like a good starting point:

   https://github.com/pexpect/pexpect/blob/master/examples/passmass.py

I, unfortunately, have to deal with Windows from time to time,
so it's still Tcl for me...

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


[Tutor] Newbie question: programs not printing

2016-03-10 Thread Patrick Craine
Hey guys,

I¹m at the very beginning of learning programming. I started using Khan
Academy and now am watching the intro course on MIT OpenCourseWare.

I downloaded Python 2.7.11 but for some reason it seems that it's not
responding the way it¹s supposed to. I haven¹t been able to figure out the
problem. I¹m on Mac OSX 10.11.3.

Here¹s an example of what¹s happening:

>>> x = int(raw_input('Enter an integer: '))
if x%2 == 0:
print 'Even'
else:
print 'Odd'
if x%3 != 0:
print 'And not divisible by 3'
Enter an integer: 3
>>> 

When I put the integer in, I understand it¹s supposed to return ³odd² or
³even,² but it¹s not giving me anything.

Also, at the top of the shell I¹m getting this message:
WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.

I¹ve downloaded and installed the program for this. Maybe there¹s something
else I¹m supposed to do?

Anyway, as you can tell, I¹m very new to this. Thanks for any help you can
offer.


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


[Tutor] Reusing Timers (threading.timer)

2012-11-13 Thread Patrick Dickey
Hi everyone,

I've got an application that will use a timer to run a function
automatically (it's an update function for my IPv6 endpoint). The
questions that I have are these:

1.  Can I stop and start the timer from different functions or methods
in my program, and if so, how?
2.  Can I stop the timer, change the value, and restart it (or would it
create a new timer), or do I have to create a new timer with an entirely
new name?
3.  If I get a value from a textbox, how do I parse it from the string
value to an integer (or float)?
4.  Is there a better way of accomplishing this task?

Here's the pseudocode for what I'm doing.

if autoUpdates is enabled
   get updateFrequency
   start timer with time value from updateFrequency
   when time is reached, run update method
else 
   cancel timer

if autoUpdates is enabled AND user changes updateFrequency
   stop timer
   get updateFrequency
   start timer with new time value from updateFrequency

The autoUpdates and updateFrequency are a checkbox and text box in
wxPython.

Thanks for any advice on this, and have a great day.:)
Patrick.


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


[Tutor] Hi, First question

2013-06-16 Thread Patrick Williams
Hi so I am making a bit of code to extract a bit of numbers data from a
file and then find the average of that data, however while I can get the
code to extract each specific piece of data I need, I can't seem to get the
numbers to add separately  so I can get a proper average. My sum1 variable
seems to only take the last bit of data entered. I was just wondering if
anyone knows what I'm doing wrong, the course I'm following hadn't started
using regex (or even proper lists) at this point, so there must be a way to
do it without. here's the code. the average of the data should be 0.6789 or
something, but I get 0.0334343 or something.

count=0
lst=list()
fname='mbox-short.txt'
fhand=open(fname)
for line in fhand:
if line.startswith('X-DSPAM-Confidence:'):
count=count+1
colpos=line.find(':')
zpos=line.find('0',colpos)
num=float(line[zpos:50])
sum1=0+num
avg=float(sum1)/int(count)
print 'Count-', count,'--', 'Average-', avg

Any help at all is appreciated, and thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] debug and execute python code in Mac

2014-08-27 Thread Patrick Thunstrom
On Wed, Aug 27, 2014 at 7:14 AM, Najam Qasim  wrote:
> What is preferable method to debug and execute python code in Mac?
>
> I do not like the cmd/terminal execution. Thanks !
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

I don't know many ways to debug code that don't involve the terminal
in some fashion. Even with a good IDE you're going to have a terminal
built in for output.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python advice about API, JSON

2014-09-29 Thread Patrick Thunstrom
On Mon, Sep 22, 2014 at 4:01 PM, Juan Christian
 wrote:
> I'm trying to make my script the more pythonic possible. How would a good
> approach regarding external API and json be?

I don't think dealing with a specific API is actually appropriate for
this list. I'll try to answer the general elements.

> I'm calling this API (http://docs.themoviedb.apiary.io/) using 'requests'.
> The thing is that I need to do a bunch of different calls to the API:
>
> - http://api.themoviedb.org/3/person << Receive ID and return person info
> - http://api.themoviedb.org/3/tv << Receive ID and return serie info
> - http://api.themoviedb.org/3/movie << Receive ID and return movie info
> - http://api.themoviedb.org/3/search << Receive "Name of person or serie or
> movie" and return ID
>
> I have the following structures:
>
> - {query}/{type}?api_key={key}&query={person or tv or movie}
> - {query}/{id}?api_key={key}
> - {query}/{id}/credits?api_key={key}
> - {query}/{id}/season/{season_numer}?api_key={key}
> - {query}/{id}/season/{season_numer}/episode/{episode_number}?api_key={key}
> -
> {query}/{id}/season/{season_numer}/episode/{episode_number}/credits?api_key={key}
>
>
> I'm thinking about creating a class 'API' and have all these URLs and
> structures there. The thing is that I need to pass my API_KEY and this key
> will be used for everything, so I just need to pass it once, how can I do
> that? Yes, I know about class attributes, but the thing is that I will call
> this class 'API' from different classes and I'll need to instantiate a API
> obj in each of them, is it a good approach? Inside this 'API' class I would
> have a __init__ that would receive an API_KEY and different methods, each
> for a type of query (person, tv, movie, search, credits).

First question: Why do you need multiple versions of this theoretical
class floating around? Perhaps if you wrote a single module api that
handles interactions with the API, you can then import that module
into any other module that will use the API, and you only have to
write all of this once.

> Maybe my explanation is a bit confusing but I hope you guys understood,
> anyway, you can ask for more information if needed!
>
> And another thing, What's better, a single module with multiple classes
> (total lines: ~110) or multiple modules with 1-3 classes (correlated, like
> class serie, season and episode in the same module, and class person and
> character in the same module) each?

I personally prefer multiple modules, though it absolutely depends on
the demands of the project.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class errors

2015-01-23 Thread Patrick Thunstrom
If the code I'm seeing is correct, the problem is the class is Jobs,
and you instantiated a Job, which doesn't exit.

Replace one with the other in either case should fix it.

On Thu, Jan 22, 2015 at 11:11 AM, jarod...@libero.it  wrote:
> Dear All,
>
> I created a class that invoke  from another file another class
>  I get an error that I do not understand: gobal name Job is not defined
> However If I see the class imported I found the class Job.
> Any suggestion or example on class invoke another class
>
> #job,py
> class Jobs:
> .
>
> #trial.py
>
> from core.job import *
> class Second:
> def __initi__:
> tp = open("/tmp/file.txt")
>
> def gus(self):
> tr = Job()
>
> thanks so much!1
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python for linux

2015-01-27 Thread Patrick Thunstrom
You're actually asking multiple subquestions here, let me start by
asking a clarifying question:

When you say "log in to the Linux machine" I assume you mean you need
to access a remote host? Your script will be running locally?

Next your other questions:

Checking permissions of a file: Look into the os module.

Checking for substrings: This is has many answers. Have you tried to
do this yet?

Patrick

On Tue, Jan 27, 2015 at 11:50 AM, Reuben  wrote:
> Hello,
>
> I wish to know which python module works well with Linux commands - for
> e.g. Searching a string in file, number of occurrences of a string in a
> file, what is the permission of a file.
>
> To test this operation I need my python script to login into the Linux
> machine and then perform the above mentioned operations
>
> Any specific pointers to help me with this task?
>
> Thanks
>
> Regards,
> Reuben
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-19 Thread Patrick Thunstrom
>>> The generalized problem:
>>>
>>> L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn .
>>> Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test
>>> value being searched for. I need to know the indices i and i + 1,
>>> which I need to interpolate based on where Vt falls.
>>>
>>> The solution (As a sublist, S)  I worked out tonight after
>>> experimenting with comprehension syntax is:
>>> S = [i for i, V in enumerate(L) if L[i] >= Vt >= L[i + 1]]
>>>
>>> And, of course, the index i I need is:
>>> i = S[0]
>>>
>>> I tested this out with concrete examples in the interpreter, such as
>>> with a list, L:
>>>
>>> L = [item for item in range(1, 0, -1)]
>>>
>>> and trying different test values. It was blazingly fast, too!
>>>
>>> All I can say is: WOW!!!
>
> By the way, if you were to use a plain old loop the expected speedup over
> the listcomp would be 2. You can break out of the loop when you have found
> the gap, after iterating over one half of the list on average.
>
> So for-loops are twice as amazing ;)

For the same basic speed up, a generator expression with a call to
next() will produce similar results. Without the additional code to
get the indexed item.

index = (i for i, _ in enumerate(original_list) if original_list[i] >=
target >= original_list[i + 1]).next()

The only catch is it raises a StopIteration exception if no element
fits the test.

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


Re: [Tutor] fibonacci.py task ???

2008-06-24 Thread John Patrick Gerdeman
Fibonacci.py calculates the Fibonacci numbers (the sum of the two
previous numbers), also see
http://en.wikipedia.org/wiki/Fibonacci_number

Files that end in .py are python files. Much like .txt are text files
and .odc is OpenOffice Calc file. 
Though you can name any file as you wish, the convention for the usual
files is to use the correct extension, so to avoid confusion.
(Sometimes it is preferable to use another extension, or to omit them
altogether, but that's not the point I'm trying to make here)

 


> 
> Fibonacci.py
> # This program calculates the Fibonacci sequence
> a = 0
We'll initialize the variable a as 0. Since the first element of the
Fibonacci Sequence is 0
> b = 1
We'll initialize the variable b as 1. Since the second element of the
Fibonacci Sequence is 1
We have to supply 0 and 1 as starting values. Without these we wouldn't
know where to start our sequence. (You could potentially start the
sequence anywhere, e.g at a=5 and b=7, or over all prime numbers, it
would still be a Fibonacci sequence, though not the one commonly known)
> count = 0
We'll initialize the variable count
> max_count = 20
We'll initialize the variable max_count
> while count < max_count:
While count is smaller then max_count do the following
> count = count + 1
Increase count
> # we need to keep track of a since we change it
> old_a = a
> old_b = b
assign a and b to two help_variables, so we don't accidently change the
values
> a = old_b
a now holds the current sequence element

> b = old_a + old_b
b holds the next element
> # Notice that the , at the end of a print statement keeps it
> # from switching to a new line
> print old_a,

I guess this is supposed to show some of the programming basics, though
I find the contents of the while-loop rather more confusing then
necessary.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor