[Tutor] SQLite database locked problem

2010-07-19 Thread Che M

I'm using an SQLite3 database (with Python 2.5) and every so often the 
application crashes or hangs because somewhere there is this error, or 
something like it:

OperationalError:  database is locked.

This is probably because I am viewing and sometimes changing the database 
through SQLite Database Browser while working on my app, and occasionally the 
app tries to access the db when the Database Browser is writing to it or 
something like that.

I'd like to a) know how to reproduce the error (haven't seen it in a while, but 
want to be sure  know when it may happen for users and b) prevent it from being 
a problem in the running app.  

Any suggestions welcome.  Thank you,
Che
  
_
Hotmail is redefining busy with tools for the New Busy. Get more from your 
inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite database locked problem

2010-07-21 Thread Che M



Date: Tue, 20 Jul 2010 07:28:45 +0200
From: cwi...@compuscan.co.za
To: pine...@hotmail.com
CC: tutor@python.org
Subject: Re: [Tutor] SQLite database locked problem






  
  


On 20/07/2010 06:48, Che M wrote:

  I'm
using an SQLite3 database (with Python 2.5) and every so often the
application crashes or hangs because somewhere there is this error, or
something like it:

  

OperationalError:  database is locked.

  

This is probably because I am viewing and sometimes changing the
database through SQLite Database Browser while working on my app, and
occasionally the app tries to access the db when the Database Browser
is writing to it or something like that.

  

I'd like to a) know how to reproduce the error (haven't seen it in a
while, but want to be sure  know when it may happen for users and b)
prevent it from being a problem in the running app.  

  

Any suggestions welcome.  Thank you,

Che

  

  Hotmail is redefining busy with tools for the New Busy. Get more
from your inbox. See how.
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  



? SQLite is technically thread safe, but a write operation locks the
entire 

> database [1]:
> - Any resultset being step()'d through uses a shared read-only lock. 

> - Any insert/update being executed requires an exclusive write lock.





Thanks, that's fine to know, but what do I do in Python to address my concern?  



Che

  
_
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with 
Hotmail. 
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Che M



> Do any of you have any feedback, strategies and best practices 
> related to unit testing within Python. This is a relatively new topic 
> for me. I was thinking of starting with reading the documentation 
> associate with the unittest module.

The idea of unit testing/test driven development has remained 
foreign to me throughout my time trying to learn Python--by choice.  
I want to make desktop GUI applications and I don't use MVC, so 
the idea of writing tests strikes me as far more work--and a major 
delayer of getting to an application that actually does something--
than simply using the software myself and noting problems.  It 
sounds like TDD is probably the most proper way to go about things, 
but, in the interest of getting something out of Python to warrant the
time I've put into it, I favor a "good enough" approach for now.




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


Re: [Tutor] web-based python?

2010-08-01 Thread Che M



> > There is a myriad of python web development frameworks. Here's a link
> > with a ton of info:
> >
> > http://wiki.python.org/moin/WebFrameworks
> I had looked into Django before. What is confusing me is that it
> sounds like it is meant to be run on the server directly. I do not
> have direct access to my server, I just rent space on it and can
> login. Maybe I am missing something, but how would I get Django onto
> my server if I do not have the physical box available to me?

For a long time I have hoped for a "Python web apps for absolute beginners"
tutorial that doesn't assume any knowledge.  For a beginner, it is not even
clear what a "web frameworks" is let alone which one he/she should start
with or if it is even needed.  I just checked Alan Gauld's Learning to Program
and was disappointed to see the section on writing web apps hasn't been
done yet, since all the other tutorial material is so good (I understand that
it is a lot of work to write these, though, and greatly appreciate all you have
already done).

Brainstorming what a good soup-to-nuts tutorial for Python web apps 
might include...

- What the the various kinds of web apps one can make are and (very) roughly 
  how much work each entails.  In other words, there is a difference between
  writing an online newspaper vs. a web based GUI app.
- Whether it matters if you develop on Windows, Linux, or Mac.
- The easiest possible "Hello, World!" (just text) in a web browser.
- How much of other languages (XHTML, CSS, Javascript, etc.) you need to know.
- What you need to understand about servers and how to communicate with them.
- How you can get more than just text on a web app, that is, widgets, and
  therefore what are currently the options for that (learning javascript and 
whatever
  widget toolkits are out there for that; qooxdoo; Pyjamas; others).
- Whether you could use Pyjamas to make your code work as both a web app
  and a desktop app.
- How you can develop your web app on your own computer and when you
  need to test it actually on the web.
- What to consider when choosing a way to host your app online.
- How to get your Python code onto that server, as well as whatever other
  code (like Django) there too. (Alex's question)
- Why starting with a MVC pattern may be the best way to go for a web app.
- What you need to consider to make your web app work the same on most browsers.
- Scalability issues, speed issues, Security issues, cost issues; etc.
- What databases to use and why
- Issues concerning whether your app can be used by iPhones and other smart 
phones.
- Opening your code to contribution; monetizing your service
- Probably lots of other stuff I don't even know about.

I understand much of this is about web apps generally and is not germane
only to Python, but it would be good if a Python tutorial at least pointed 
toward
this information, since for many beginners, the entry portal to anything is 
through
Python.  To just refer someone to Django when they don't know the first thing 
about
web apps is, I think, off-putting.

Che


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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Che M



> > The idea of unit testing/test driven development has remained
> > foreign to me throughout my time trying to learn Python--by choice.
> > I want to make desktop GUI applications and I don't use MVC, so
> > the idea of writing tests strikes me as far more work--and a major
> > delayer of getting to an application that actually does something--
> > than simply using the software myself and noting problems.  It
> > sounds like TDD is probably the most proper way to go about things,
> > but, in the interest of getting something out of Python to warrant the
> > time I've put into it, I favor a "good enough" approach for now.
> 
> Writers just call this a rough draft. Perfection is in the revisions
> that come after a little thought.

Well, I don't see what I'm doing as a rough draft, as I am attempting
to hone it to "perfection" (that is, a working app)--just without unit testing.

A different analogy comes to my mind; I once saw two different sets of
people analyze data.  One did it "by hand":  visually inspecting thousands
of signals herself and typing Y or N to accept or reject each signal.  The
other did it with an automated system that accepted or rejected signals 
based on fuzzy logic.  In an important interpretation, the automated system 
was far better, and yet the first scientist was done with her analysis and
accepted for publication before the second team even had the bugs worked 
out of the automated system!  Yes, I think the slow-but-more-proper team
did the more correct thing, but there is something to be said for "good
enough", too (it works for evolution, for example).



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


Re: [Tutor] Where to start with Unit Testing

2010-08-02 Thread Che M

 
> Che, from the analogies you made, it looks like you might not have very
> clear what Unit Testing is for.
> 
> True, UT is a way to automate tests that otherwise you should do
> manually (as per your analogy), but the test you automate with UT are
> not a "one off" thing (as it is processing the data needed to publish a
> paper): depending on the coding philosophy you follow, you might run UT
> as often as every couple of hours of coding (as it is in certain agile
> programming techniques).
> 
> UT is there to give you a tool to prevent regression *when/if you modify
> or refactor your code* (which is the norm if you are a professional
> programmer), and its advantages grow exponentially with the increase of
> complexity of the code and the increase of number of developers working
> on the project (it is very easy to break someone's else code... there is
> a reason for which "blame" - http://blame.sourceforge.net/ - is called
> that way!).
> 
> If you are an hobbyist programmer busy on a simple one-off small app,
> you may skip UT altogether, manually inspect the behaviour of your
> program, and never regret it. 
> 
> But if you are writing an e-commerce application that will organise
> transaction for millions of euros of revenue monthly, UT is probably the
> very first code you will want to commit to your repo.

Mac, I found this an excellent brief overview of UT and your points all
seem very strong to me.  Thanks very much.  I admit I didn't really know
anything about the topic and was mentioning my feelings on the matter
partly to elicit enlightening responses like this (maybe because I was feeling 
like I was being irresponsible with my own project by not learning UT 
and running tests).  

I am in the "hobbyist programmer busy on a simple one-off small app"
camp ("simple" is relative...though it is clearly nothing like a big 
e-commerce application!), so I feel OK with foregoing getting into UT 
for now.  If things get more complex and I at some point have actual users
instead of the large number of vapor users I have now (:D) I may buckle
down and learn it.

> PS: I did not comment on the analogy with evolution, because did not get
> the parallelism you were trying to draw. Care to explain?

I just meant that evolution by natural selection works on a "good enough"
principle:  that successful species evolve not toward the most perfected
forms but the forms that are simply good enough to allow them to pass
on enough of their genes to stay in the game.  And sometimes "good
enough" is good enough--that is, you shouldn't waste your time doing
things perfectly properly. In my case, I thought doing things perfectly 
properly would be learning all about UT and bringing that into my 
development process--but manual inspection would be "good enough".
(But now I see that really it *is* proper to skip UT if the project doesn't 
warrant it).

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


[Tutor] global exception handling?

2010-08-02 Thread Che M

A week or two back I asked this list about how to deal with SQLite database 
errors like 'database is locked'.  Since then I figured out one way to 
reproduce that error (*see p.s. below if anyone is interested).  I can also 
then catch the error with a try/except block and prevent it from causing 
problems.

But, the issue is, I have many places where I write to the database and would 
have to embed each of these in a try/except block.  I can do that, but wondered 
if there is a "global" way to catch this 'database is locked' error?  I found 
someone asking this sort of question online but it doesn't appear to be 
answered:
http://bytes.com/topic/python/answers/799486-how-do-i-prevent-exceptions-stopping-execution-global-exception-handler

Thanks,
Che

p.s. *I use the nice program SQLite Database Browser and if I edit a field in
 the database my Python app is accessing, click "Apply changes", but I do *not* 
save the changes (that is, I do not click the disk icon), when I go to write
 to that database from my Python app, I get a 'database is locked' error.

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


Re: [Tutor] web-based python?

2010-08-02 Thread Che M



Thanks, Alan, for this set of helpful pointers.  Just a few responses.

> Actually web apps are all pretty similar. They consist of three basic 
> parts
> (maybe 4):
> 1) A mechanism for mapping a URL to a Python function or method.
> 2) A mechanism for generating HTML with embedded data values
> 3) A data storage mechanism
> 4) Some client code for a more dynamic feel

What does "client code" and "more dynamic feel" mean here?

> > - The easiest possible "Hello, World!" (just text) in a web browser.
> 
> Hello, World!
> 
> That's it as a one liner.

I guess I meant the easiest possible "Hello, World!" that incorporates
Python and works through a server, etc.  This is just the HTML.  And
even with this, a total beginner will have no idea that he or she should
copy that into a Notepad window, save it as helloworld.html, and then
open that file from Firefox to see it as HTML.  The point is, in many
discussions of web programming all the elements (and there are 
many) are scattered and disconnected from the concrete steps one 
needs to take to put them into working order.  

I recall that CherryPy has a little walk-through on how to get something
very simple working with it, and that's closer to what I'm recommending.
(Though obviously you're just answering bullet points in an email and
this is not your tutorial :D ).

> If you want it as a CGI program in Python its only slightly longer
> and the CGI documentation shows you how...

Probably that's what I'm after, but my guess is the CGI documentation
is not particularly approachable (though haven't checked).  A beginner
would also not know where "the" CGI documentation is.

> > - How you can get more than just text on a web app, that is, 
> > widgets, and
> >   therefore what are currently the options for that (learning 
> > javascript and whatever
> >   widget toolkits are out there for that; qooxdoo; Pyjamas; others).
> 
> This is where it gets very complicated. 

And yet I think this what it's all about.  When beginners think about
a web app (or dynamic web page as someone else here put it), they
don't think about HTML and text going back and forth to/from a server, 
they think about widgets similar to widgets seen on the desktop 
(calendars, buttons, textboxes, checkboxes, etc.).  I was excited to
see the Quooxdoo widget set and heard it might be possible to use
it with a Python backend...via JSON (which I don't know about) but
it was too nebulous to motivate pursuing when I am still working on
learning desktop programming.

> > - How you can develop your web app on your own computer and when you
> >   need to test it actually on the web.
> 
> Thats usually just a case of running a web server on your PC.

And that's its own topic.  "Running a web server on your PC" rings zero
bells for beginners.  

> Wikipedia is your friend and the partial topic that I did on web
> programming did include some of the basic stuff with lots of
> links to Wikipedia articles.

I don't think Wikipedia is the beginner's friend on this sort of thing.
I have not found it good for learning how to program.  Just looking
at the topic "web development" shows this; it is an overview of the
field, but there is no instructional/tutorial material.  It doesn't teach
how to do it.

> HTH,

It is helpful, and like anything one can probably work his or her way through
the topic slowly and stumblingly, but I do think that a thorough starting-with-
zero-knowledge-and-defining-all-terms tutorial would be a wonderful thing to 
have.  As you said before, web programming is a lot more involved than 
desktop programming.  I think it would be really a fun challenge to put
together a great soup-to-nuts tutorial on this (but I am far from the one
to do it!), since it incorporates so many elements.  I wish you luck on
the Py3 tutorial and and web app tutorial work when you have the chance.

Thanks,
Che

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


Re: [Tutor] global exception handling?

2010-08-04 Thread Che M


> > But, the issue is, I have many places where I write to the database and 
> > would have to embed each of these in a try/except block.  I can do that, 
> > but wondered if there is a "global" way to catch this 'database is locked' 
> > error?  I found someone asking this sort of question online but it doesn't 
> > appear to be answered:
> > http://bytes.com/topic/python/answers/799486-how-do-i-prevent-exceptions-stopping-execution-global-exception-handler
> 
> I'm not sure why you would like to do that: your code assumes the database 
> interaction works fine, and based on that just continues it's normal flow. If 
> the database is locked, you'll need to do something to prevent your code 
> crashing further down, which is what you put in the except OperationalError: 
> block. I would assume that the error handling depends on where you are in the 
> code.
> If you can always perform the same type of error handling, just create a 
> convenience function (possibly with the SQL statement as argument) that calls 
> the database and returns the results, and put the database call inside the 
> try: except: clause. Then you need to do this only once.

Interesting, it didn't occur to me to do that.  I may give it a try.  Since I 
am making INSERTs and UPDATEs to the database from all over the application (in 
different modules), maybe I should put this error-handling convenience function 
in a module and import it into every other module, then I can just use it.  
Unfortunately, I'll still have to go back and find every instance of when I do 
INSERT or UPDATE to change this to use the convenience function, but it will 
still save me some keystrokes to fix the app.

> A global way to catch the database-locked exception is just to put the try: 
> except OperationalError: around your complete code. Exceptions propagate all 
> the way to the function where your program started, and if you catch it 
> there, you will catch every OperationalError exception from anywhere in the 
> code. Of course, your program then always exits anyway, because you can't 
> return to the point where the the exception was thrown (or maybe you can, but 
> not that I'm aware of. I wouldn't recommend it though).

That I really didn't know at all.  But yes, if the program exits, that's not 
going to work.

> > > p.s. *I use the nice program SQLite Database Browser and if I edit a 
> > > field in the database my Python app is accessing, click "Apply changes", 
> > > but I do *not* save the changes (that is, I do not click the disk icon), 
> > > when I go to write to that database from my Python app, I get a 'database 
> > > is locked' error.

> Sounds like somewhat odd behaviour to me: "apply changes" for me means "apply 
> & commit", ie, it includes the save operation. Might 
> just be me.  I guess "Apply changes" opens the database connection, but then 
> "save" performs the actual commit to the database, and 
> in the meantime the database is locked.

I don't know, either, but I was glad to find a way to reproduce the problem so 
that I could anticipate it for potential users.

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


Re: [Tutor] Distributing Python Code for Commercial Porpoises?

2010-08-06 Thread Che M


> #, showing his output. We need to make sure we are on the same playing 
> ground with numpy and scipy. I don't think we are. He barely knows 
> Python, but did, supposedly, a install of it, numpy and scipy from the 
> same written direction I use. I think he mistakenly installed a 
> different version of numpy. So how can we make sure we or anyone are on 
> the same playing field? 

Both of you do this from IDLE:

import numpy
help(numpy)

Read the version # at the end.
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Databases in Python

2010-08-24 Thread Che M

> The other day, I wrote a little database just to fiddle around, 
> but when I try to run it it says that it has an unexpected indent. 
> From what I can tell, it doesn't. Here's the code. I'm using SPE.

In the future, you should copy/paste error message you get into
your email.  This way it indicates to others the exact problem you
had.

One thing I noticed that is wrong in your code is this line:

if searcher in database:# Figure this out.  
The comment doesn't count as a line of interpretable code, so
you have nothing in this code block.  If you want to do that, use
pass, like:

if searcher in database:pass
# Figure this out.  
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating custom GUI elements

2010-09-04 Thread Che M



> How would I go about creating custom GUI elements? For example, 
> if I wanted to make a simple LEGO maker app, how would I write the 
> code for the bricks so that the user could drag them around and then 
> build LEGO models?

For 2D legos, using the wxPython widget toolkit, you could probably use 
its widget called FloatCanvas to provide a space in which bitmaps can be 
moved around a screen and their coordinates tracked.  Then you would 
have to write the code that determines if the bitmap of the brick is in the 
right position to snap into place with another brick.

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


Re: [Tutor] Creating custom GUI elements

2010-09-05 Thread Che M




> Would Pygame allow me to code all of the bricks instead of drawing them out?

I've never used Pygame; I have no idea.  What I was suggesting was just getting
a picture of a real or Lego-like brick from somewhere and using that image in
your program.  No drawing required.



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


Re: [Tutor] confused with dates and which way to start

2009-02-18 Thread Che M



> From: jfabi...@yolo.com
> To: tutor@python.org
> Date: Wed, 18 Feb 2009 15:55:05 -0800
> Subject: Re: [Tutor] confused with dates and which way to start
> 
> On Wednesday 18 February 2009 03:10:41 pm johnf wrote:
> > Hi,
> >
> > I need to develope a routine that will provide the some dates between a
> > starting date and an ending date.  The dates will be used to schedule
> > instructors for specific class dates from the list of available dates.
> > Class is normally on Monday, Wedesday, and Friday (or any days of the week
> > including Sat and Sun).  If the length of the class is 6 months (01/01/09 -
> > 06/30/09).  I need to generate all the dates that would match the Monday,
> > Wedesday, and Friday (or whatever days are used for the class) for the
> > entire period.
> >
> > I have done this is FoxPro in the past.  Now I'm in python 2.5.
> >
> > Now the problem is there appears many ways to deal with dates in python.
> > time(), calendar(), datetime(), dateutil().  Which is the easy way guys???
> > And is there something already written I should be using  Also there is
> > something called 'mx'.
> >
> > Thanks in advance.
> 
> Kent Johnson provided the following:
> 
> This is pretty easy using datetime.date and timedelta. For example,
> this shows all the M, W, F between (more or less) your given dates:
> 
> In [1]: from datetime import date, timedelta
> In [3]: end = date(2009, 6, 30)
> In [4]: start = date(2009, 1, 4) # a Sunday
> In [7]: offsets = [timedelta(days=offset) for offset in (1, 3, 5) ] #
> Mon, Wed, Fri
> In [8]: current = start
> 
> In [9]: while current < end:
>...: for offset in offsets:
>...: print current + offset
>...: current += timedelta(days=7)
> 
> 2009-01-05
> 2009-01-07
> 2009-01-09
> 2009-01-12
> 2009-01-14
> 2009-01-16
> ...etc
> 
> Kent
> 
> 
> thanks Kent.  This appears to work.  I was not aware of datetime.timedelta(). 
>  
> I really think there should be a place to find this type of information.  
> I'll study the module.  Again, thanks.

Well, if you Google "dates Python", three page-downs down the first hit and it 
shows about datetime.timedelta().  It's also mentioned in the second hit.  Of 
course, it does require scanning and reading, since you start unsure of what to 
be on the lookout for.  

I'd also recommend you look at dateutil, because it is expressly for doing what 
you need, in case you need to do more and more complex date work.  The page 
includes a ton of example code:
http://labix.org/python-dateutil

_
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] weather scraping with Beautiful Soup

2009-07-16 Thread Che M

Hi, 

I am interested in gathering simple weather data using Beautiful Soup, but am 
having trouble understanding what I'm doing.  I have searched the archives and 
so far haven't found enough to get me moving forward.

Basically I am trying to start off this example:

Grabbing Weather Underground Data with BeautifulSoup
http://flowingdata.com/2007/07/09/grabbing-weather-underground-data-with-beautifulsoup/

But I get to the exact same problem that this other person got to in this post:
http://groups.google.com/group/beautifulsoup/browse_thread/thread/13eb3dbf713b8a4a

Unfortunately, that post never gives enough help for me to understand how to 
solve that person's or my problem.

What I want to understand is how to find the bits of data you want--in this 
case, say, today's average temperature and whether it was clear or 
cloudy--within a web page, and then indicate that to Beautiful Soup.

Thanks,
Che

_
Windows Live™: Keep your life in sync. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_BR_life_in_synch_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M


> The posts basocally say go and look at the HTML and find the
> right tags for the data you need. This is fubndamental to any kind of web
> scraping, you need to understand the HTML tree well enough to identify
> where yourt data exists.
> 
> How familiar are you with HTML and its structures?

Reasonably familiar.

> Can you view the source in your browser and identify the heirarchy
> of tags to the place where your data lives?

I can view the source, and have made my own web pages (HTML, CSS).
I am less sure about the hierarchy of tags.  For example, here is the
section around the current temperature:


West of Town, Jamestown, Pennsylvania 
(PWS)
Updated: 3:00 AM 
EDT on July 17, 2009





http://icons-pe.wxug.com/i/c/a/nt_clear.gif"; width="42" height="42" 
alt="Clear" class="condIcon" />


  60.3 °F


The 60.3 is the value I want to extract.  It appears to be down within a 
hierarchy
something like:



 
   
 


But I am far from sure I got all that right; it is not easy to 
look at HTML and match  with .  Unless I am missing
something?  Do I have to use all of the above in my Beautiful
Soup?
CM

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M



> Date: Fri, 17 Jul 2009 12:27:36 +0200
> From: mot...@xs4all.nl
> To: tutor@python.org
> CC: pine...@hotmail.com
> Subject: Re: [Tutor] weather scraping with Beautiful Soup
> 
> Che M wrote:
> 
> > The 60.3 is the value I want to extract.
> 
> soup.find("div",id="curcondbox").findNext("span","b").renderContents()


Thanks, but that isn't working for me.  Here's my code:

-
import urllib2
from BeautifulSoup import BeautifulSoup

url = "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=43085";
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

daytemp = soup.find("div",id="curcondbox").findNext("span","b").renderContents()

print "Today's temperature in Worthington is: ", daytemp
-

When I try this, I get this error:

HTMLParseError: malformed start tag, at line 1516, column 60

Could someone suggest how to proceed?

Thanks.
CM



_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M



> Date: Fri, 17 Jul 2009 08:09:10 -0400
> Subject: Re: [Tutor] weather scraping with Beautiful Soup
> From: ken...@tds.net
> To: pine...@hotmail.com
> CC: tutor@python.org
> 
> On Thu, Jul 16, 2009 at 11:21 PM, Che M wrote:
> > Hi,
> >
> > I am interested in gathering simple weather data using Beautiful Soup, but
> > am having trouble understanding what I'm doing.  I have searched the
> > archives and so far haven't found enough to get me moving forward.
> >
> > Basically I am trying to start off this example:
> >
> > Grabbing Weather Underground Data with BeautifulSoup
> > http://flowingdata.com/2007/07/09/grabbing-weather-underground-data-with-beautifulsoup/
> >
> > But I get to the exact same problem that this other person got to in this
> > post:
> > http://groups.google.com/group/beautifulsoup/browse_thread/thread/13eb3dbf713b8a4a
> >
> > Unfortunately, that post never gives enough help for me to understand how to
> > solve that person's or my problem.
> >
> > What I want to understand is how to find the bits of data you want--in this
> > case, say, today's average temperature and whether it was clear or
> > cloudy--within a web page, and then indicate that to Beautiful Soup.
> 
> One thing that might help is to use the Lite page, if you are not
> already. It has much less formatting and extraneous information to
> wade through. 


I was not aware Weather Underground had a Lite page; thank you, that
is good to know.  It was easier to figure things out in that HTML.

I am getting closer, but still a bit stuck.  Here is my code for the Lite page:


import urllib2
from BeautifulSoup import BeautifulSoup

url = 
"http://www.wund.com/cgi-bin/findweather/getForecast?query=Worthington%2C+OH";
page = urllib2.urlopen(url)

soup = BeautifulSoup(page)
daytemp = soup.find("div",id="main").findNext("h3").renderContents()

print "Today's temperature in Worthington is: ", daytemp
-

This works, but gives this output:

>>> 
Today's temperature in Worthington is:  
75 °F

Of course, I just want the 75, not the HTML tags, etc. around it.  But I am not 
sure
how to indicate that in Beautiful Soup.  So, for example, if I change the 
soup.find
line above to this (to incorporate the ):

daytemp = soup.find("div",id="main").findNext("h3", "span").renderContents()

then I get the following error:

AttributeError: 'NoneType' object has no attribute 'renderContents'

(I also don't understand what the point of having a  tag with no style
content in the page?)

Any help is appreciated.  This still feels kind of arcane, but I want to 
understand
the general approach to doing this, as later I want to try other weather facts
or screen scraping generally.

Thanks.
CM




You might also look for a site that has weather data
> formatted for computer. For example the NOAA has forcast data
> available as plain text:
> http://forecast.weather.gov/product.php?site=NWS&issuedby=BOX&product=CCF&format=txt&version=1&glossary=0
> 
> Kent

_
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M



> Date: Fri, 17 Jul 2009 20:02:22 +0200
> From: mot...@xs4all.nl
> To: tutor@python.org
> CC: pine...@hotmail.com
> Subject: Re: [Tutor] weather scraping with Beautiful Soup
> 
> Che M wrote:
> 
> > "http://www.wund.com/cgi-bin/findweather/getForecast?query=Worthington%2C+OH";
>  >
> > Any help is appreciated.  
> 
> That would be:
> 
>daytemp = soup.find("div",id="main").findNext("span").renderContents()
> 

Thank you, that works!  I'll go try some more things and read more of
the documentation and if I bump into more confusions I may have more
questions.

Che

_
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M


> 2009/7/17 Michiel Overtoom :
> > This is actually the first time I see that BeautifulSoup is NOT able to
> > parse a webpage...
> 
> Depends on which version is used. If 3.1 then it is much worse with
> malformed html than prior releases. See [1] for more info.
> 
> Greets
> Sander
> 
> [1] http://www.crummy.com/software/BeautifulSoup/3.1-problems.html

YesI just read about the 3.1 problems, and switched to 3.07a, re-ran
the exact same code as befor...and it worked perfectly this time.  

(For those novices who are unsure of how to install a previous version,
I found that I only had to simply clear out what BS files I had already
under site-packages, and just put the Beautiful Soup.py 3.0.7a file found 
on the website into that site-packages folder...very easy).

Lots of useful information today, thank you to everyone.

Che

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M


OK, got the very basic case to work when using Beautiful Soup 3.0.7a and 
scraping the Weather Underground Lite page.  That gives me the current 
temperature, etc.  Good.

But now I would like the average temperature from, say, yesterday.  I am again 
having trouble finding elements in the soup.  This is the code:

--
import urllib2
from BeautifulSoup import BeautifulSoup

url = 
"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KPAJAMES1&month=7&day=16&year=2009";
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

table = soup.find("td",id="dataTable tm10")
print table



When I look at the page source for that page, there is this section, which 
contains the "dataTable tm10" table I want to zoom in on:




 
Current:
High:
Low:
Average:




Temperature:

  73.6 °F


  83.3 °F


  64.2 °F


  74.1 °F

--

And yet when I run the above code, what it prints is:

>> None

In other words, it is not finding that table.  Why?  

Help appreciated again.
Che


_
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Che M



> Date: Sat, 18 Jul 2009 01:09:32 +0200
> From: sander.swe...@gmail.com
> To: tutor@python.org
> Subject: Re: [Tutor] weather scraping with Beautiful Soup
> 
> 2009/7/17 Che M :
> > table = soup.find("td",id="dataTable tm10")
> 
> Almost right. attrs should normall be a dict so {'class':'dataTable
> tm10'} but you can use a shortcut, read on.
> 
> > 
> >
> > When I look at the page source for that page, there is this section, which
> > contains the "dataTable tm10" table I want to zoom in on:
> >
> > 
> > 
> > 
> > 
> >  
> > Current:
> > High:
> > Low:
> > Average:
> > 
> > 
> > 
> > 
> > Temperature:
> > 
> >   73.6 °F
> > 
> > 
> >   83.3 °F
> > 
> > 
> >   64.2 °F
> > 
> > 
> >   74.1 °F
> > 
> > --
> 
> The tag you are looking for is table not td. The tag td is inside the
> table tag. So with shortcut it looks like,
> 
> table = soup.find("table","dataTable tm10")
> 
> or without shortcut,
> 
> table = soup.find("table",{'class':'dataTable tm10'})
> 
> Greets
> Sander

Thank you.  I was able to find the table in the soup this way.  

After a surprising amount of tinkering (for some reason this Soup is more like
chowder than broth for me still), I was able to get my goal, that 74.1 above,
using this:

---
import urllib2
from BeautifulSoup import BeautifulSoup

url = 
"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KPAJAMES1&month=7&day=16&year=2009";
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

table = soup.find("table","dataTable tm10")  #find the table
tbody = table.find("tbody")  #find the table's body

alltd = tbody.findAll('td')  #find all the td's
temp_full = alltd[4] #identify the 4th td, the one I 
want.
print 'temp_full = ', temp_full
temp = temp_full.findNext('span','b').renderContents()  #into the span and b 
and render
print 'temp = ', temp
--

Does this seem like the right (most efficient/readable) way to do this?

Thanks for your time.
CM


_
Hotmail® has ever-growing storage! Don’t worry about storage limits. 
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hitting a wall (not a collision detection question :P)

2009-07-19 Thread Che M

So, I'm just wondering what I should be doing at this point. Sorry for the 
vague question, but I'm pretty lost right now and this is about as specific as 
I can be. Thanks in advance for any help.

Michae

I started from scratch a 3 years ago and my advice would be:

- Accept confusion.  Marinate in it.  Don't fight it.  Clarity will come, with 
time.  It is easy to get overwhelmed early.  Take a break, get some hours of 
slow wave sleep, it will be clearer next time you engage it, probably.

- "I'm in a hurry, so dress me slowly".  Clarity and rushing don't mix well 
ever, but it is particularly bad with computer code.


- Make your function names meaningful:  long enough to tell what they do.  Make 
functions verbs, like GetDatabaseInformation(), and not just Database() or 
worse, D().  (This is my opinion, at least).  And comment your own practice 
code with explanations if that is helpful to you.

- Keep a notebook/file of what you have learned and where to find it again 
online if you need to refresh.

- Use this list and other lists (if there is a pyGame list, e.g.).  Great 
people in the Python community.  Ask good questions, too:  
http://catb.org/esr/faqs/smart-questions.html

- Once you have the basics a bit beyond "Hello, World!", don't just try to 
learn everything--learn *per task*.  So find what task you want, and try 
something simple to begin, establish that, and then move on.  

- Tutorials I've enjoyed and learned from:

Alan Gauld's Learning to Program
http://www.freenetpages.co.uk/hp/alan.gauld/

Effbot's Guide to the Standard Python Library 
http://effbot.org/zone/librarybook-index.htm

Various Beginner video screencasts on ShowMeDo, incl. lots on beginning Python.
www.showMeDo.com

Good luck,
Che



_
Bing™ brings you maps, menus, and reviews organized in one place. Try it now.
http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TXT_MLOGEN_Local_Local_Restaurants_1x1___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] code structure terminology and advice

2009-07-21 Thread Che M

Hi, this is really more of a general programming question than a Python 
question, though perhaps there is a Python-relevant set of terms/answers to 
it... I'm trying to refactor some code to be more structurally "proper", more 
easily maintained, etc.  Doing some "thinking out loud", and I have two 
questions:  

Q1) Generally, what is the best structure for when there are a number of 
steps/actions that need to be taken?  Q2) Is there a term/some jargon in 
programming that refers to the difference between examples 1-3 below?

Examples:  Let's say I have some wish to perform four related sequential 
actions--steps, let's call them--in some part of the program.  In terms of 
grouping those actions, there are 3 ways I can think to do this (pseudocode):

1. Do the steps all in one function:

def Function(self):
  do step1 action
  do step2 action
  do step3 action 
  do step4 action

2. Have each step be a function, and have each function call the next function 
in the chain:



def StepOne(self):

   do step1 action

   self.StepTwo()



def StepTwo(self):

   do step2 action

   self.StepThree()


3. Make each step a function, but call all of them in order in one master 
function:

def MasterFunction(self):
  self.StepOne()
  self.StepTwo()
  self.StepThree()
  self.StepFour()

(elsewhere these functions are defined)

etc...


It seems to me that example 3 is the most sensible.  1 is bad because the steps 
should be functions, because then they can be easily reused, seen from an IDE 
explorer, etc. (I guess if they are really minor things it isn't necessary). 2 
is terrible because it introduces far too much dependence and might be hard to 
maintain.  It is also possible to sort of mix aspects of all of these...that 
also seems jumbled.

Maybe there are other and better ways to think about organizing a sequence of 
steps, and if so I'd love to hear them.  I'd also like to know what I might 
look up to read up on managing this kind of thing.

Thanks,
Che

_
Windows Live™ Hotmail®: Search, add, and share the web’s latest sports videos. 
Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_videos_072009&cat=sports___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] code structure terminology and advice

2009-07-22 Thread Che M



> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Wed, 22 Jul 2009 08:46:04 +0100
> Subject: Re: [Tutor] code structure terminology and advice
> 
> 
> "Che M"  wrote 
> 
> You pretty much answered your own question.
> 
> The ultimate answer depends on a few other contextual issues.
> 
> > Q1) Generally, what is the best structure for when there are 
> > a number of steps/actions that need to be taken?  
> 
> A sequence! :-)
> 
> > Q2) Is there a term/some jargon in programming that 
> > refers to the difference between examples 1-3 below?
> 
> Not that I'm aware of.
> 
> >  wish to perform four related sequential actions--steps, 
> > let's call them--in some part of the program.  
> 
> If the entire program consists of those 4 steps (as in a batch 
> data processing program, say) then you might structure things 
> differently than if the 4 steps are only part of a bigger 
> program - one menu option out of several, say.
> 
> In the former you would perform the steps in sequence and 
> may or may not put them in functions.depending on whether 
> they would ever be reused and how long the code was per step.
> In most cases the steps are likely to be reusable or of significant 
> length so you would put each one in its own function.
> 
> > 1. Do the steps all in one function:
> > 
> > def Function(self):
> >   do step1 action
> >   do step2 action
> >   do step3 action 
> >   do step4 action
> 
> This would be sensible in the menu selection context.
> 
> > 2. Have each step be a function, and have each function 
> > call the next function in the chain:
> 
> No, this is terrrible from every point of view. It removes any 
> opportunity of reuise of individual steps and builds up a deep 
> call stack which makes debugging harder and the coupling 
> between functions makes maintenance harder (for example 
> swapping two steps around in the sequence)
> 
> > def StepOne(self):
> >do step1 action
> >StepTwo()
> 
> > 3. Make each step a function, but call all of them in order in 
> > one master function:
> > 
> > def MasterFunction(self):
> >self.StepOne()
> >self.StepTwo()
> 
> This is just a variation on option 1 and the same applies.
> 
> The fourth option you do not consider but which could be the 
> best solution for the batch program I discussed is just to perform 
> each step from the top klevel of the program, ie no 
> enclosing function
> 
> StepOne()
> StepTwo()
> StepThree()
> StepFour()
> 
> 
> > It seems to me that example 3 is the most sensible.  
> 
> In general yes.
> 
> > 1 is bad because the steps should be functions, because then they 
> > can be easily reused, seen from an IDE explorer, etc. 
> > (I guess if they are really minor things it isn't necessary). 
> 
> This depends on the size of the steps and the nature of the overall 
> programme, but functions would usually be best.
> 
> > 2 is terrible 
> 
> Yes.
> 
> > Maybe there are other and better ways to think about organizing 
> > a sequence of steps, and if so I'd love to hear them.  
> 
> For longer and more complex processes you could use a table 
> or list of functions and step through them in a loop
> 
> process = [StepOne, StepTwo,, stepN]
> 
> for step in process:
>  step()
> 
> Or for dynamically changing sequences you can create or hold 
> a sequence list and use that to index a list of steps:
> 
> steps = [StepOne, StepTwo,, stepN]
> sequence = [1,2,3,4]
> 
> def do Process(sequence)
> for step in sequence:
>  steps[step]()
> 
> This allows you to selectively peform some of the steps:
> 
> sequence = [1,3,4,N]
> 
> doProcess(sequence)
> 
> Finally for very complex scenarios you might implement a 
> state machine where the return value of each step controls 
> the next step in the sequence. That can be done by building 
> a set of state objects or using a data driven approach with 
> a table
> 
> You can read about state machines in several places, 
> I'd start with Wikipedia.
> 
> You might also find that reading about business process execution
> languages gives you some ideas about how to structure and 
> represent complex processes. BEPL would be a good 
> starting point, again try Wikipedia.
> 
> HTH,
> 
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/

Thank you, Alan.  It is sometimes helpful just to get corroboration, and I feel 
that sometimes the simplest things are the most imp

Re: [Tutor] mnemonics to better learn Python

2009-07-23 Thread Che M



> Date: Thu, 23 Jul 2009 14:05:36 +0800
> From: ld...@gmx.net
> To: Tutor@python.org
> Subject: [Tutor] mnemonics to better learn Python
> 
> Dear List,
> 
> in order to memorize which Python sequences are mutable or immutable, I
> focused on the SHAPE of the brackets that are associated with each type
> of sequence.
> 
> For instance, a *list* is characterised by square brackets, [].
> My mnemonic device to memorize that lists are mutable is this: "the
> brackets have sharp edges, they could be trimmed, taking their edges off".
> 
> The same thing happens with *dictionaries* (which, okay, are not
> sequences). Anyway, their brackets, {}, have sharp edges, hence they are
> mutable.
> 
> *Tuples*, in turn, have perfectly 'round' brackets, (), and these
> brackets obviously can't be improved upon by taking anything off them.
> Hence: tuples are immutable.
> 
> That leaves us with *strings*, which are also not mutable. Here we have
> no brackets, and this particular mnemonic device breaks down.
> 
> What I am interested in is finding out whether you use similar
> techniques, and if so, which ones? How, for examples, do you make sense
> of all those special characters that make regular expressions powerful?
> Do you rely on rote learning, or do you employ some other technique?
> 
> I reckon that if we could come up with some tips and techniques as to
> how to uncloud the thick information fog that any beginning programmer
> has to wade through, the very first steps in learning Python could be
> made more easy.
> 
> What insights can you share?

I am all for mnemonics and have used them to good effect in learning and 
teaching; students' abilities to memorize large lists of biological terms and 
such are greatly increased this way.  But so far it hadn't occurred to me to 
apply mnemonics to learning Python.  This is because I have seen learning 
Python as less about memorizing content and more about understanding concepts.  
Others may see it differently, but that is how it has seemed to me.  Compared 
to biology, where words are based on Greek or Latin (e.g. "postzygopophysis"), 
and there may be many such odd terms per topic, Python is mostly based in 
simple English words like random, string, open, etc.  What was harder, coming 
from a cold start, was how to use the language, "grokking" things like self, 
list comprehensions, namespaces, = vs ==, Boolean stuff, exceptions, lambdas, 
decorators, etc.  Also, importantly, I tend to have ready access to the web to 
look things up if I forget them, like whether it is .split() or .join() that I 
want to use.  But your idea to mnemonicize some of your learning could no doubt 
be helpful to speed you along, since looking things up does slow one down (and 
can derail one's thought stream as one is trying to figure out why the program 
is not working as expected).  

_
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need to start learning again

2009-07-25 Thread Che M



> From: fredp...@mac.com
> To: tutor@python.org
> Date: Sat, 25 Jul 2009 16:24:13 -0700
> Subject: [Tutor] Need to start learning again
> 
> I started learning python, but then life got busy...  I need some help  
> finding good resources to start learning again.
> 
> My main need for python at first would be to write small programs to  
> perform system commands.  Like moving files around, copying or  
> deleting files, and perhaps some simple interface construction so I  
> can create a window to show the status of the little programs i plan  
> to write.
> 
> Any help would be appreciated.

For file manipulation, take a look at this:
http://effbot.org/librarybook/os.htm

And yes, Tkinter probably would make things easier for a simple GUI.

_
Windows Live™ Hotmail®: Celebrate the moment with your favorite sports pics. 
Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_photos_072009&cat=sports___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] simple text replace

2009-07-26 Thread Che M


> I am scanning a text file and replacing words with alternatives. My 
> difficulty 
> is that all occurrences are replaced (even if they are part of another 
> word!)..

Could you search for the string ' word ' with the white spaces around it?  
Shouldn't
that only replace words that are not part of another word?

> Essentially, I would like to replace only the occurrence that is currently 
> selected-- not the rest. for example:


What do you mean by a word being "currently selected"?  That phrase and
"scanning a text file" don't make sense to me together.  How is the user 
reading the text to select the word that is to be replaced?  (Or maybe I am
not understanding something?)

CM

_
Bing™ brings you maps, menus, and reviews organized in one place. Try it now.
http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TXT_MLOGEN_Local_Local_Restaurants_1x1___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] self.name vs. passing a name

2009-07-27 Thread Che M

This is another very basic structural question, related to one I asked last 
week, and again is not necessarily germane only to Python.

Let's say you have a sequence of two calculations or manipulations you need to 
do, each one done as a function called by an overall calculate_something() 
function.  The "answer" to each function is then used in the next function.  I 
can think of two ways to make that answer available for use in the next 
function:  1) pass it in, or 2) declare it as self.answer and then it is 
available to the whole class instance.

What are the dis/advantages to these two different ways?  Here are examples, 
with only the overall calculate_something() function shown:

1.Pass the variable to the second function.

def calculate_something(self):
answer = self.do_first_calculation()#1st function returns answer
self.do_second_calculation(answer)#2nd is passed answer and uses it.

2. Create the variable in the class instance scope and use that in the second 
function.

def calculate_something(self):

self.do_first_calculation() #1st function creates 
self.answer

self.do_second_calculation() #2nd uses self.answer

Both of these approaches can work, but I would like to better understand when 
it is best to do one or the other.  Obviously if I know I will need to make 
self.answer available for use by other functions, I would want to choose (2).  
But what other considerations should I, well, consider?

Thanks,
Che





_
NEW mobile Hotmail. Optimized for YOUR phone.  Click here.
http://windowslive.com/Mobile?ocid=TXT_TAGLM_WL_CS_MB_new_hotmail_072009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] self.name vs. passing a name

2009-07-28 Thread Che M


> > The "answer" to each function is then used in the next function.
> > I can think of two ways to make that answer available ...
> >   1) pass it in, or
> >   2) declare it as self.answer

Thank you Alan, Kent, and Dave.  Full agreement, and it makes sense
to me.  (Maybe this is also an example of "explicit is better than implicit"?)

Che

_
Windows Live™ Hotmail®: Celebrate the moment with your favorite sports pics. 
Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_photos_072009&cat=sports___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Currency conversion module in python

2009-07-30 Thread Che M

Did you actually look at what happens when you click that
link?  (i.e. where you are brought to?).  

Because upon viewing this I achieved enlightenment!  :D


Date: Thu, 30 Jul 2009 10:02:39 +0200
From: zebr...@gmail.com
To: amit.pureene...@gmail.com
CC: tutor@python.org
Subject: Re: [Tutor] Currency conversion module in python

Hi Amit, this might be what you want..hopefully with a dollop of humor :)

http://lmgtfy.com/?q=currency+conversion+module+in+python&l=1


Cheers

On Thu, Jul 30, 2009 at 12:45 AM, Amit Sethi  wrote:

Hi , Does anybody know of any currency conversion module in python



--

A-M-I-T S|S

___

Tutor maillist  -  Tutor@python.org

http://mail.python.org/mailman/listinfo/tutor



-- 
Lloyd Dube

_
Windows Live™ Hotmail®: Celebrate the moment with your favorite sports pics. 
Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_photos_072009&cat=sports___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mnemonics to better learn Python

2009-07-31 Thread Che M



> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Fri, 31 Jul 2009 17:09:48 +0100
> Subject: Re: [Tutor] mnemonics to better learn Python
> 
> 
> "Eduardo Vieira"  wrote
> 
> > Hello, would anybody have a good memorization technique for boolean
> > results? Like when using 'or'/'and' what it returns when both are
> > false, the last is false, etc?
> 
> Hmm, I don't try to remember those, I just work it out based on 
> the meaning. 
> 
> A and B is true only if both A and B are True
> A or B is true if either A or B is True.
> 
> Thats it really, what's to remember?

I tend to agree, but since he asked for a mnemonic...

What Python Needs to Return a Boolean
AND:  Both I demand! 
OR:One or more.  

So,

if A and B are False:
 [think "Both I demand...are False")
if A or B are False:
 [think "One or more...are False")
if A and B are True:
 [think "Both I demand...are True")
etc.

Che


_
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Che M


> Start a CMD window and run the python command by typing the command
> at the DOS prompt.
> 
> eg
> 
> C:\Windows> python some\path\to\myscript.py
> 
> 
> That way you will still see the error message after the
> program finishes.

Or what about using IDLE?  



_
Express your personality in color! Preview and select themes for Hotmail®. 
http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_express:082009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] simple plots

2009-08-21 Thread Che M


> I would like to make some simple plots using matplotlib (or any python 
> plotting 
> modules) and I can find lots of examples that generate random data and then 
> plot those, but I cannot find any that read in data from excel or a text 
> file, 
> manipulate the data and then plot the data. Does anyone have any examples 
> for this or webpages I could go to?

Keep in mind, too, that in terms of matplotlib, for simple plots all you need to
feed the plot() function is a list of x points and a list of y points.  
Sometimes
the demos on their web page might seem to obscure this for beginners because
of the fancy math functions that make pretty plots, but that's all you need:
two lists.

Getting those two lists of points is what you are really concerned about, as 
Kent indicated, and so this is not really a matplotlib concern.  And as he said,
Python has lots of good support for that. 

Che

_
Hotmail® is up to 70% faster. Now good news travels really fast. 
http://windowslive.com/online/hotmail?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_faster:082009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxpython question

2009-09-09 Thread Che M



Date: Wed, 9 Sep 2009 15:52:53 -0400
From: krissy.amb...@gmail.com
To: tutor@python.org
Subject: [Tutor] wxpython question

Hi,
I'm not sure if I could ask questions about wx in this list or not, hopefully 
it's okay? If not I guess disregard this question.
But, does anyone have any idea of if it's possible to make a frame that will 
latch on to the parent frame (e.g. if you resize the parent, the child also 
resizes, if you move the parent, the child also moves), aside from using the 
MDI window that's wxpython provides?

-- 
Cheers,
Krissy 
---
Testing the waters is always fun...

__

Although people on this list would likely be happy to try to help, there
is a wxPython users list that is really good:

http://www.wxpython.org/maillist.php

You can do what you are saying, although I don't think there is any
built-in way to do it.  You would have to use the two frames' methods
of getting and setting position on the screen and then bind the Move
event of the parent frame to an event handler function that then
updates the position of the child (following) frame.  The people on
that list can help you if you have further questions.

CM

_
Get back to school stuff for them and cashback for you.
http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Challenge

2009-09-22 Thread Che M


> I wrote this code but I know its wrong. Although it works properly:

> flips=0
> h='heads'
> t='tails'
> while True:
>flips+=1
>if flips>100:
>break
>if True:
>print(flips,'=',h or t)

> But
it prints every number with the string 'heads'. I'm really blank at
this. It may have 
> something to do with the 'random' module.

Keep in mind, you never import the random module in this code,
so the problem could have nothing to do with that module.  When
you use a module in Python, you import it, and there will be a line
at the top like this:

import random

Read up on importing modules; they are very important (pardon the
pun) in Python.  The random module, like most of the modules, has
lots of functions in it for cases where randomization is needed.  You
can read up on it:  http://docs.python.org/library/random.html

I also really like Effbot's guide to the modules; for example, for random:
http://effbot.org/librarybook/random.htm

Che


_
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/___
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-06 Thread Che M



> programming language. The problem is, I don't know which to learn. I want a 
> language 
> that will be good for me to learn, 

Good for you in what way?  Is there a general "good for you" for programming, 
or do you need to achieve a certain goal?  From a jobs point of view, Java 
seems pretty in-demand.  From a stretching-your-mind point of view, maybe a 
rather different language would be better?

> I tried learning C++ and it was a massive failure, 

Earlier today today I picked up "C++ for Dummies" for $0.25 at a library sale 
bin just on the off chance I might try to learn a bit of it.  Not sure I will.  
But I'm curious:  why was it a massive failure?  

Che
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Methods that return instances of their own class?

2009-10-15 Thread Che M



> In particular, I'm trying to run a simple prisoner's dilemma game, and  
> I want to make a "game" object that has a method which returns the  
> "game" object with the payoffs reversed; that is, the payoff matrix  
> from the other player's point of view.  Basically a kind of transpose  
> which is specific to this application.

Since this is the tutor list, I'd like to ask some questions about
structures used here that I haven't encountered before.  I hope
you'll excuse me asking instead of Googling them, but words like
list and value are tough to get the relevant sense of them for
these cases...
 
> class Payoffs(list):
>  def __init__(self, value=None):
>  list.__init__(self)

This class is a list that has methods?  That seems sort
of unusual to me.  Am I interpreting that right?

How is this class called?  With a list AND a value?  What
does it mean to initialize a list (the third line?).  

>  if value==None: # use a default prisoner's dilemma
>  value=[[(3,3),(0,5)],
> [(5,0),(1,1)]]
>  self.extend(value)

This means that the list that is the instantiation of this
class is being extended by the hardcoded values given
here.  But if value == None, was there any list to extend,
or was it an empty list, []?  Why not just pass a list and
to a class directly, and if not use a default list without
having to use .extend()?  There is no case here in which
a passed-in list would be extended with a hardcoded list,
correct?
 
>  def __repr__(self):

>  l1="Your Choice:   CooperateDefect\n"
>  l2="My choice:   -\n"
>  l3="Cooperate| (% 3d,% 3d) | (% 3d,% 3d) |\n" % (self[0] 
> [0][0], self[0][0][1], self[0][1][0], self[0][1][1])
>  l4="  --- \n"
>  l5="Defect   | (% 3d,% 3d) | (% 3d,% 3d) |\n" % (self[1] 
> [0][0], self[1][0][1], self[1][1][0], self[1][1][1])
>  l6=" -\n"
>  return l1+l2+l3+l4+l5+l6

What is the reason for using __repr__() here and also
this |1 style?  I have not seen this before. 

>  def transpose(self):
> 
> And that's where I'm at.  How can I have the transpose method return  
> another Payoffs object?  Here's the beginning of it:
> 
>  def transpose(self):
>  trans=[[(self[0][0][1],self[0][0][0]), (self[1][0][1],self[1] 
> [0][0])],
> [(self[0][1][1],self[0][1][0]), (self[1][1][1],self[1] 
> [1][0])]]

Did this have to be hardcoded like this, or is there a more
Pythonic way to transpose the payoff list?  Maybe it needs
to look like this, but this does not strike me as very readable.

Thanks for any future insight,
Che



  
_
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/171222985/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite database not update correctly

2009-11-08 Thread Che M









> I've got a functions that should update an sqlite database, among other 
> things.  However
>  the database doesn't get updated. When used in isolation, the update 
> statement works 
> fine. What am I doing wrong?

> Below is the function. The whole script can be found at 
> http://pastebin.com/m53978ffa

I think it's because you don't commit the changes to the database.  Use 
c.commit() after
you make the changes.

  
_
Find the right PC with Windows 7 and Windows Live. 
http://www.microsoft.com/Windows/pc-scout/laptop-set-criteria.aspx?cbid=wl&filt=200,2400,10,19,1,3,1,7,50,650,2,12,0,1000&cat=1,2,3,4,5,6&brands=5,6,7,8,9,10,11,12,13,14,15,16&addf=4,5,9&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen2:112009___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite database not update correctly

2009-11-09 Thread Che M


> It's working fine now, but actually I didn't write exactly what you 
> suggested. 
> The "commit" method belongs to the connection, not to the cursor. Therefore, 
> in my script it should be conn.commit().

Whoops, you're quite right.  Went a little too fast there.  :D

Che
  
_
Windows 7: Unclutter your desktop.
http://go.microsoft.com/?linkid=9690331&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen:112009___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting Data in Databases

2009-11-23 Thread Che M


Ken,



I would also recommend trying out databases, if you have an interest. 
I found them a fun new aspect of using Python.  I would recommend using
SQLite, which very conveniently comes with Python.  Alan Gauld's
tutorial that you've read part of has a nice section on Working with Databases, 
and it uses
SQLite as the example database management system.  

Understanding a bit
about how to use SQL (the Structured Query Language that most databases
use, but which is surprisingly close to English) is also a good thing
to learn as you learn about programming generally.  I thought it was going to 
be harder than it turned out to be.  It's not bad.  Another good helper is 
http://sqlzoo.net/.  What you will want to "Google up on" once you are ready to 
try to sort your database is "ORDER BY" in the context of SQLite.



Good luck,

Che   
_
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting Data in Databases

2009-11-24 Thread Che M


> That is a surprise to me.  I did not know that Python would work with
SQLite.   

Sure, as someone else said, Python comes with a LOT of libraries built right
in when you download Python.  This is known as "batteries included", that is,
what comes with the standard distribution of Python.  

> I will look into Alan's tutorial on DB. 

It is of course thorough and will really provide understanding.  But just to
emphasize how simple creating a SQLite database in Python is, I recommend
you do these 4 simple steps:

1. Download and install the very nice SQLite Database Browser application, 
from here:
http://sourceforge.net/projects/sqlitebrowser/

It's simple and good.  

2. Now open IDLE (which also comes with Python), do File > New Window,
and paste this simple Python code into that window:

#--
#get SQLite into Python...it's that simple!
import sqlite3

#Make a connection to a database...if it doesn't exist yet, we'll create it.
conn = sqlite3.connect('my_database.db')   

#Create a "cursor", a kind of "pen" that writes into the database.
cur = conn.cursor()

#Write a table, called here MyTable, into the database, and give it two fields,
# name and address.
cur.execute('''CREATE TABLE if not exists MyTable (name, address)''')

#Now actually write some data into the table you made:
cur.execute('INSERT INTO MyTable VALUES(?,?)',('John','Chicago'))

#Always have to commit any changes--or they don't "stick"!
conn.commit()

#You're done!
#--

Without the comments, (which explain a bit about why it is written
as it is) this is just this small an amount of Python code--6 lines:

import sqlite3

conn = sqlite3.connect('my_database.db')   

cur = conn.cursor()

cur.execute('''CREATE TABLE if not exists MyTable (name, address)''')

cur.execute('INSERT INTO MyTable VALUES(?,?)',('John','Chicago'))

conn.commit()


3. Run your program in IDLE (Run > Run Module...or just hit F5).  Save
it to your Desktop.

4. Now view your handiwork in the SQLite Database Browser.  Open
it and then do File > Open Database, then find a file on your Desktop
called mydatabase.db.  Open it.  Now you are looking at the database
you just made.  Click on the Browse Data tab and you are now seeing
that John lives in Chicago.

It's that simple to at least get started.  Thanks, Python.

Che










 I am getting more
and more surprised of what Python can do.  Very comprehensive.   Thanks
all.




Ken 
  
_
Bing brings you maps, menus, and reviews organized in one place.
http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class understanding

2009-11-24 Thread Che M



> Date: Tue, 24 Nov 2009 10:27:05 -0600
> From: jammer10...@gmail.com
> To: tutor@python.org
> Subject: [Tutor] Class understanding
> 
> Hi all... Have been attempting to understand classes... Been getting
> along without them for a while now and feel it's time to jump in
> 
> What I want to do it start a log with the logging module... I have
> this working without classes, but want to try... Here is a snippet of
> the code that I am hacking on:

I'm sure the better explainers will jump in presently, but let me try
a few tips...

> class logger():

The convention in Python is to make class names capitalized.  It is
not necessary, but it is a good habit to get into, so class Logger().

> import logging

Imports are traditionally done at the top of a Python file, not within
a class. 

> logger()

This calls the class but doesn't create a name for an instance of
the class, so you won't be able to access it later.  Instead, try
(assuming you rename logger() to Logger() ),

logger_instance = Logger()

Now you have a name for that instance of the class, and so
can access the goodies inside the class.  

> logger.write2log(log_info)

So that would now be:

logger_instance.write2log(log_info)

> encouragement, or pointers to good docs would be helpful... I've done
> a lot of searching via Google on classes, and it's all confusing to
> me...

Keep trying.  There have to be tons of good tutorials on classes.
They fall under the heading of "Object Oriented Programming".   I tend
to think of a class as a "container" that has all the stuff you will need
to do a certain set of actions.  It can contain data (facts) and it can 
contain methods (functions).  You can create one or more "instances"
of any class (a traditional example being that Dog() is a class whereas
fluffy is an instance of a dog, and therefore has all the traditional dog
methods, like bark(), wag(), etc.)

CM







  
_
Windows 7: It works the way you want. Learn more.
http://www.microsoft.com/Windows/windows-7/default.aspx?ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen:112009v2___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] functions--how long is too long?

2009-12-07 Thread Che M

I have some functions that seem kind of long to me.  One of them, with
white space, comments, print statements, and some commented-out lines,
is 118 lines long.  If I remove all that, it is 57 lines long.  I get the sense
that is inappropriately long for a Python function.  

The length of it is due to a number of if statements--things it needs to
check in terms of the state of the app at the time it is called.  So there
are a number of conditional (and "subconditional") parts to it, and what
it does in response to those conditions.  In fact the word "if" appears in
it 12 times.  

I realize I can and should refactor parts that are used in other places
in the code, but I don't there are that many in some of these.  Is
there a better way to think about organizing this?

Thanks,
Che
  
_
Windows Live Hotmail gives you a free,exclusive  gift.
http://www.microsoft.com/windows/windowslive/hotmail_bl1/hotmail_bl1.aspx?ocid=PID23879::T:WLMTAGL:ON:WL:en-ww:WM_IMHM_7:092009___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions--how long is too long?

2009-12-08 Thread Che M

Thank you to all who replied.  That does help me get a better
idea of all this.  I think if I apply a number of the thoughts
expressed I can come to a good, readable re-do of these
longer functions.  

Che
  
_
Chat with Messenger straight from your Hotmail inbox.
http://www.microsoft.com/windows/windowslive/hotmail_bl1/hotmail_bl1.aspx?ocid=PID23879::T:WLMTAGL:ON:WL:en-ww:WM_IMHM_4:092009___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-09 Thread Che M



> My problem, though, is I still find it difficult to write meaningful code or 
> use the built in libraries 

> effectively and/or correctly because I can't find example code to mimic. I 
> tried sifting through 

> ActiveState recipes page, but most of the code seems uninteresting or useful 
> only if utilized 

> in a bigger project. 

What do you mean by "meaningful" code?  I think that might be your issue.  



What I'd recommend is to figure out *what you want to accomplish*.  Python is 
just a means

to accomplish something, but what matters is the accomplishment.  You may want 
to write a 

GUI desktop app for a specific purpose.  You may want to create a web-based 
app.  You may

want to write code to process information, scrape web sites...create a game, 
create some

kind of tool.  



Once you decide on that, you will be more focused on what you need to learn.  
If, for

example, you need to have persistent storage of information, you then might 
want to

read up on databases and perhaps SQLite in Python.  Etc.  Then you will find 
code that

will be applicable to your concerns, and help you learn.  I feel that learning 
something 

"in a vacuum", unrelated to some personal creative goal, just doesn't work well.



Che

  
_
Get gifts for them and cashback for you. Try Bing now.
http://www.bing.com/shopping/search?q=xbox+games&scope=cashback&form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_Shopping_Giftsforthem_cashback_1x1___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-09 Thread Che M



> But the reason I ask this, is because there are SO many different approaches 
> you could
> take to a single problem, 

I guess that depends a lot on what sorts of problems you are thinking in terms 
of.  At least in many cases, perhaps one of the points of the Zen of Python is 
useful:

"There should be one--and preferably only one--obvious way to do it."



I myself have been trying to stick to that for now; to learn some standard ways 
to do certain things, to not reinvent the wheel but instead to use the standard 
library and modules to do what I need done (since someone already needed it 
done before and coded it well then).Yes, gaining more flexibility in how 
you could approach something is also good, but for learning I have tried to 
establish a core of basic approaches first, and alternate approaches second.  I 
feel that if it works, it's readable, simple, and re-usable, I put it in the 
toolbox.

> how do you know which is correct or why one is better than the 
> other?  You can dig yourself in to holes with more complex problems, and not 
> understand 
> why. 

This list is one good resource for comparing notes on "correctness" of 
approach.  You'll see people ask if something is "Pythonic" or not, etc.


  
_
Windows 7: Unclutter your desktop. Learn more.
http://www.microsoft.com/windows/windows-7/videos-tours.aspx?h=7sec&slideid=1&media=aero-shake-7second&listid=1&stop=1&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_7secdemo:122009___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-11 Thread Che M



> I won't continue to divert this thread from good books, but I will continue 
> to look 
> for more and more tutorials and will post it  The more the more merrier...


> Becky 

Just on that topic of tutorials, have you seen www.ShowMeDo.com?  
They have right now 516 screencast tutorials related (directly or indirectly)
to Python.  This way you can watch a video and usually hear a person
describing what they are doing and why.  Oftentimes, videos are organized 
into a series on a particular topic, like GUI programming, databases, etc.
It's a different way to learn, and I find it a great service to the Python
(and other programming or computer use) community.

Che
  
_
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/171222984/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with if

2007-05-24 Thread Che M
I'm not sure what the whole indentation thing is for.  And now I'm having 
trouble with the if statement things.


Maybe your if statement troubles have been solved by others by now, but I'll 
just add that "the indentation thing" is a vital feature of Python, it is 
the way to separate code blocks.  Other languages uses other means, like 
curly braces, etc.  I get the sense those who like Python enjoy indentation 
because it forces the code to be quite readable, and I agree.  See this:


http://www.diveintopython.org/getting_to_know_python/indenting_code.html

Also, as mentioned previously, keep in mind that 2 is not the same as "2" 
and "=" is not the same as "==".  The single "=" is used to assign names to 
objects, whereas the == is for evaluating something, so for if statements 
use == and not =.  Also note you can put "and" along with if, so you can say


if x == "mom" and y == "dad":
   print "my parents"

and lots of other stuff.
-Che

_
PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows 
Live Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507


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


[Tutor] monitor other running applications with Python?

2007-05-26 Thread Che M
Hi, searched a bit for this but haven't found much.  Is it possible to use 
Python to monitor the use of other applications? (anything...Word, Excel, 
browsers, etc.)


At minimum, I wan't to know that the application was running, but even 
better would be some sense of the use or content, such as whether the app 
was idle or the user was using it, or, for a web browser, what URLs were 
visited and for how long, etc.  Ideally I'd like a cross-platforms approach 
but expect that might be hard.  I know utilities like this are out there, 
but I have no sense how to go about this in Python, or how difficult it 
might be.  Any ideas are appreciated.


Thanks,
Che

_
Like the way Microsoft Office Outlook works? You’ll love Windows Live 
Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_outlook_0507


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


Re: [Tutor] monitor other running applications with Py

2007-05-30 Thread Che M
Thanks for the pointers, Alan.  It seems perhaps a bit beyond my abilities 
for now, but something to keep in mind for the future if I get that far.  
And yes, the legal aspects are worth noting, though rest assured my wish for 
such a thing is for self-monitoring rather than other-monitoring, though I 
can see how it could get used nefariously if not cautious.


Best,
Che


Date: Sun, 27 May 2007 15:54:11 +0100
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] monitor other running applications with Python?
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
    reply-type=original

"Che M" <[EMAIL PROTECTED]> wrote

> Hi, searched a bit for this but haven't found much.
> Is it possible to use Python to monitor the use of
> other applications?

Yes, definitely.

> At minimum, I wan't to know that the application was running

Thats fairly easy using OS tools such as ps on Unix.
You can dig a little deeper and use the system APIs such
as the proc fiilesystem or the equivalent in the windows
registry.

> better would be some sense of the use or content, such
> as whether the app was idle or the user was using it,
> or, for a web browser, what URLs were visited and for
> how long, etc.

Thats possible but gets very OS specific and very low level too.
On Windows you can catch Windows events and messages
using some of the raw Win32 API calls from the ctypes module.
(I've never used ctypes for anything this low level but it
should be possible, I''ve certainly done it in C++ and Delphi
on Win 9X). But its messy and fairly deep Windows magic
and you will need to spend a fair bit of time experimenting
and reading the docs on MSDN as well as the Win32 API
help file.

> Ideally I'd like a cross-platforms approach

I doubt if that's possible except at the process monitoring
level. For the kind of detail you want the bgestb you can
do is have a common UI and pluggable modules based
on the OS.

Also beware legal implications. There are issues around
personal privacy, data proptection etc and these vary between
countries (and even states in the US). People are increasingly
wary of Big Brother style monitoring. Detecting inappropriate
use of the internet across a corporate firwall is generally
considered OK but silently monitoring individuals brings you
into murky legal waters.

Finally, take a look at the stuff in the os package and the
syslog module for Unix.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



--

Message: 2
Date: Sun, 27 May 2007 12:25:17 -0500
From: adam urbas <[EMAIL PROTECTED]>
Subject: [Tutor] error message questions
To: python tutor 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="windows-1252"

Hello all,I was wondering if there would be someone who would be able to 
give me a list of error messages and their meanings.  I've attached this 
test.py to illustrate my problem.  When I run the program, I am able to 
enter all the data, yet it will not calculate.It says:can't multiply 
sequence by non-int of type 'str'I really would like to know how to fix 
this.I get a similar message with my other one, radiacir.py:can't multiply 
sequence by non-int of type 'float'Please help!Thanks in advance,Adam

_
Change is good. See what?s different about Windows Live Hotmail.
http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507
-- next part --
An HTML attachment was scrubbed...
URL: 
http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment.html

-- next part --
An embedded and charset-unspecified text was scrubbed...
Name: test.py
Url: 
http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.pot

-- next part --
An embedded and charset-unspecified text was scrubbed...
Name: radiacir.py
Url: 
http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.asc


--

Message: 3
Date: Sun, 27 May 2007 12:49:04 -0500
From: adam urbas <[EMAIL PROTECTED]>
Subject: Re: [Tutor] trouble with "if"
To: Brian van den Broek <[EMAIL PROTECTED]>
Cc: python tutor 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="windows-1252"

Thank you for the help Brian.  I would like to ask you about these things.  
Which one of the examples you gave would be most fool proof.> Date: Wed, 23 
May 2007 13:40:09 -0400> From: [EMAIL PROTECTED]> To: 
[EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] trouble 
with "if"

Re: [Tutor] Tutor Digest, Vol 40, Issue 54

2007-06-23 Thread Che M
regarding making an executable file from a python file, Alan Gauld said:

>Assuming you are on Windows you can use py2exe but
>its non trivial to use. (Not hard, just not trivial)
>
>But first ask why you need to.
>I've been using Python for over 10 years now and never once needed
>to do this. (I did it once just to see how, but I've never *needed* to
>do it)
>
>Once Python is installed you can run any script by just double
>clicking in explorer.
>
>And you can build installers that will install python if its not
>already there and then add your script. There are few cases
>where you really need an exe file. IMHO.

Though, yes, you never need to, perhaps you might *want* to, for reasons of 
"marketability".  For example...if I want to make an application for 
distribution to others, either for sale or as freeware, and I use the 
installers option as you mentioned, it is only proper to indicate this to 
the end user, such as, "In installing this application, the Python 
programming language and some other libraries will also be installed on your 
computer."

But that might trigger a common psychological response from the user, "Oh, 
no, not a whole complex set of things installed on my computer that I don't 
understand, have never heard of, and will only need for this one 
application"  But downloading a single .exe file and maybe a small folder of 
images or a few .dll files doesn't conjure that sense.  If I understand it 
right, the .exe has Python bundled into it anyway, so such an end user's 
response isn't strictly rational, but you can see how people might feel this 
way in an age when there are so many ways one should mistrust software.

Another reason is that, as I understand it, making it an .exe obscures the 
code (at least enough to make it take a bit more work to reveal the code).  
For some this might be a benefit?

I may be way off base here, just throwing it out as something I've wondered 
about.

_
Get a preview of Live Earth, the hottest event this summer - only on MSN 
http://liveearth.msn.com?source=msntaglineliveearthhm

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


[Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M

Hi, I am trying to simply create an SQLite database with Python.  I find 
that when I try to create a new database file, *sometimes* it lets me do it, 
and sometimes it doesn't, and the only thing I am changing is the name of 
the database.  I am baffled as to why some names appear to work and some 
don't.  For example, this will create a brand new database on the desktop:

import sqlite3
conn = sqlite3.connect('C:\Documents and 
Settings\user\Desktop\mydatabase.db')

But running *this*--only thing different is the database's name--gives the 
error, as shown:

import sqlite3
conn = sqlite3.connect('C:\Documents and 
Settings\user\Desktop\adatabase.db')

Traceback (most recent call last):
  File "C:/Documents and Settings/user/Desktop/sqlitetester", line 5, in 

conn = sqlite3.connect('C:\Documents and 
Settings\user\Desktop\adatabase.db')
OperationalError: unable to open database file

The only thing that is different is one is called "mydatabase.db" (works) 
and the other is called "adatabase.db" (doesn't work).

I've tested lots of different names, and it seems random to me what will 
work and what won't.  E.g., "banana.db" and "apple.db" don't work, but 
"peach.db" and "pear.db" do It is also consistent with each name (that is, 
if I am successful and then remove the .db file from the desktop, that name 
will always work again to create a new .db file).

None of this makes any sense:  it should be able to use anything, shouldn't 
it?  I assume I am missing something obvious.  Any help would help restore 
sanity to acceptable levels.  Thanks.

_
Booking a flight? Know when to buy with airfare predictions on MSN Travel. 
http://travel.msn.com/Articles/aboutfarecast.aspx&ocid=T001MSN25A07001

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


Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M
Thank you Alan and Roel for the insight, and Roel thank you for all the 
suggested ways to get around it.  It's always nice when something goes from 
making no sense to making complete sense in a snap.

Che

_
Booking a flight? Know when to buy with airfare predictions on MSN Travel. 
http://travel.msn.com/Articles/aboutfarecast.aspx&ocid=T001MSN25A07001

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


[Tutor] tagging pieces of information

2007-08-27 Thread Che M
Hi, I am curious about ways in Python to approach the idea of "tagging" 
pieces of information much in the way that one can tag favorite websites 
like on the site Del.icio.us.  I'm not sure if tagging is the best term for 
this (due to confusion with HTML tags), but the idea would be a way to 
assign one or more words to stored data such that later one might search by 
those words in order to retrieve the data.  That data might be a chunk of 
text, a graph, image, whatever...the point would be to be able to search 
later by tags name.  I know the prorgram GyrFalcon uses tags and is written 
in Python.  And of course Flickr and many other things.

I don't know if there are any preexisting Python structures which would help 
with this or if it has to be done by scratch, or if it is easy or difficult. 
  I also don't know what are good ideas for ways to save the tags, whether 
in a text file, in a database (if so, comma separated in one cell?), or some 
other means, and how to associate them with the data chunk they refer to, 
and lastly how to search for them.

Some starting points in the right direction, jargon words to search for, 
etc., would be very helpful.  Thanks.

_
Learn.Laugh.Share. Reallivemoms is right place! 
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

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


Re: [Tutor] tagging pieces of information

2007-08-29 Thread Che M


> > Hi, I am curious about ways in Python to approach the idea of "tagging"
> > pieces of information much in the way that one can tag favorite websites
> > like on the site Del.icio.us.  I'm not sure if tagging is the best term 
>for
> > this (due to confusion with HTML tags), but the idea would be a way to
> > assign one or more words to stored data such that later one might search 
>by
> > those words in order to retrieve the data.  That data might be a chunk 
>of
> > text, a graph, image, whatever...the point would be to be able to search
> > later by tags name.  I know the prorgram GyrFalcon uses tags and is 
>written
> > in Python.  And of course Flickr and many other things.
>
>A simple way to do this in-memory would be to use a dict: keys are
>tags and values are sets (or lists) of objects.  You might need to
>maintain an inverse structure too, mapping object to list/set of tags.
>
>You could use a database (sqlite comes with python 2.5).  I'm not sure
>what the "best practice" strucutre would be, but maybe you could have
>a table with two columns: "object ID" and "tag".  "object ID" would be
>some kind of identifier for your tagged objects.  You could then:
>
>Find tags for an object:
>  select tag from tagTable where objectID = ?
>
>Find objects matching a tag:
>  select objectID from tagTable where tag = ?
>
>--
>John.

Thanks, John, I've fooled around with the database way to do it and
it fits in nicely with other things I'm trying to do and should work well
for me.  Thanks to the others for their suggestions as well.
-Che

_
Puzzles, trivia teasers, word scrambles and more. Play for your chance to 
win! http://club.live.com/home.aspx?icid=CLUB_hotmailtextlink

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


[Tutor] date matching with python and sqlite3

2007-08-31 Thread Che M
I'm trying to allow users to select data from an sqlite database using 
Python by choosing either a date or a range of dates.  I'm stuck at just 
allowing the to select data that entered the database "today" and return 
values from a column called duration.  I have this mess at the moment:

#assume they have already chosen this self.datechoice to be today

if self.datechoice == "today":
todaystring = str(datetime.datetime.today())
today = todaystring[0:10]
cur.execute('SELECT duration FROM datatable WHERE date =' + '"' + today 
+ '"')

The 3rd line is a way to take just the first part 10 chars of the 
datetime.today string, so
instead of "2007-09-01 12:00:03" it would be just "2007-09-01", since I just 
want
to match it to today, not a particular time during today.  But this only 
works if the
dates have been saved that way--typically they are saved with the time as 
well, so
this method is not good and obviously not the right way to do it.

I can tell I am going about this totally wrongly and that I should be able 
to use either
the Python datetime functions or SQLite's date functions much better, so any 
insight
would be appreciated.   Thank you.

_
A place for moms to take a break! 
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

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


Re: [Tutor] date matching with python and sqlite3

2007-09-01 Thread Che M

Re: date matching with python and sqlite3


I sorry, maybe I am stupid at the moment but I cannot follow your
question,


I'm sorry, I didn't describe that too clearly...have coffee now, let's
try that again.

The user will have a choicebox that has options of "today", "this week", 
"this month",
etc., as well as a way to just provide a range of dates, e.g. "Jan 1 
2007--Apr 15 2007".
The point is I want them to be able to get data from the database for 
whatever time
period they want.  Let's say the data is type of fruit they ate on various 
dates.  So
they would put in "this month" and it would return all the fruit that was 
eaten that
month.  And every time they indicate they ate a fruit, they enter it into 
the database
and Python will save it as a datetime object, which has the format 
2007-09-01 12:00:00.
My trouble is in how to write the SQL statements to match the date(s) they 
need

while ignoring the time part of the datetime.

For example, the code I have for matching to "today" doesn't work because it 
will
match a date saved as "2007-09-01" but not "2007-09-01 12:03:03", and it is 
this
2nd format that the datetime object takes.  I also prefer that format, 
actually, in

case I later want to sort by time of day.

Again, this is the non-working and inelegant code:

if self.datechoice == "today":
   todaystring = str(datetime.datetime.today())
   today = todaystring[0:10]
   cur.execute('SELECT duration FROM datatable WHERE date =' + '"' + today
+ '"')

I'm sure there is an easy way to do this since both Python and SQLite have
date functions, but I have just had trouble understanding the SQlite 
documentation.
Sorry if this is more an SQLite concern than a Python concern, but it is 
sort of on

the border.  If this is still unclear I will try again.  Thanks!

_
Get a FREE small business Web site and more from Microsoft® Office Live! 
http://clk.atdmt.com/MRT/go/aub0930003811mrt/direct/01/


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


[Tutor] user-given variable names for objects

2007-12-12 Thread Che M





I'm sure this is a classic beginner's topic, and I've read a bit about it 
online already, but I'd like to ask about it here as well.  I want to assign 
names to objects based on what a user inputs so that I can later keep track of 
them. 

In particular, I want to time multiple events by getting each of their start 
times and later comparing them to their respective stop times--I don't want to 
user timers.  In order to do this, I need to give each start time a name 
associated with the name of the event.  If there is an "event A" it's start 
time could be eventA_start, whereas event B could be called eventB_start, i.e.:

eventA_start = datetime.datetime.now() 

The problem is, I don't know the "A" part...the user could choose eventPotato 
or eventDinosaur.  I won't know in advance.  I want the name chosen/inputted by 
the user to be attached to the name for the time that event started.

I have read that the way to do this properly in Python is with use of 
dictionaries, but I haven't found a reference online that shows how to do it is 
in a complete way.  Any help is appreciated.

_
Share life as it happens with the new Windows Live.
http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_122007___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] user-given variable names for objects

2007-12-13 Thread Che M



> To: tutor@python.org
> From: [EMAIL PROTECTED]
> Date: Thu, 13 Dec 2007 07:53:36 +
> Subject: Re: [Tutor] user-given variable names for objects
> 
> 
> "Che M" <[EMAIL PROTECTED]> wrote 
> 
> > I'm sure this is a classic beginner's topic, 
> 
> Indeed it is, it comes up about once a month or more!
> 
> > I want to assign names to objects based on what a 
> > user inputs so that I can later keep track of them. 
> 
> This is almost never what you want to do, for precisely 
> the reason that you can't keep trackl of them when you 
> stop using the >>> prompt. Insteaed you should probably 
> use a dictionary to collect these user based objects 
> based on their names.
> 
> There is a section  on this in the OOP topic in my tutorial
> 
> > ...In order to do this, I need to give each start time 
> > a name associated with the name of the event.  
> > If there is an "event A" it's start time could be 
> > eventA_start, whereas event B could be called eventB_start
> 
> So create a dictionary called events and access them using
> 
> events['A']
> events['B']
> 
> etc.
> 
> > The problem is, I don't know the "A" part... the user could 
> > choose eventPotato or eventDinosaur.  I won't know in advance.  
> 
> Which is why you can't write code to use variables whose 
> names you don't know when writing the code. That's why putting 
> them in a dictionary is a better solution. You just get the name 
> as a string and use it as a key in the dictionary. Just watch out 
> for duplicate names.
> 
> > I have read that the way to do this properly in Python is with 
> > use of dictionaries, but I haven't found a reference online that 
> > shows how to do it is in a complete way.  Any help is appreciated.
> 
> Check the bank account example in my tutorial, under the 
> section heading "collections of objects".
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 



Thank you, indeed it did help.  For some reason when I was reading
about dictionaries online I got the unfortunate thought that the value
couldn't be a function--glad I was highly incorrect on that one.  I had
also been shy of understanding how to use dictionaries for some reason (fear of 
hyphens and curly braces?),
but your section and a little trying it out in IDLE makes it seem
do-able.  I'll give it more of a go later and see if I can get things
moving ahead. 


_
The best games are on Xbox 360.  Click here for a special offer on an Xbox 360 
Console.
http://www.xbox.com/en-US/hardware/wheretobuy/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] user-given variable names for objects

2007-12-13 Thread Che M



> Date: Thu, 13 Dec 2007 01:58:10 -0600
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: tutor@python.org
> Subject: Re: [Tutor] user-given variable names for objects
> 
> Che M wrote:
> > I'm sure this is a classic beginner's topic, and I've read a bit about 
> > it online already, but I'd like to ask about it here as well.  I want 
> > to assign names to objects based on what a user inputs so that I can 
> > later keep track of them.
> Yes, this comes up quite a bit.
> > In particular, I want to time multiple events by getting each of their 
> > start times and later comparing them to their respective stop times--I 
> > don't want to user timers.  In order to do this, I need to give each 
> > start time a name associated with the name of the event.  If there is 
> > an "event A" it's start time could be eventA_start, whereas event B 
> > could be called eventB_start, i.e.:
> >
> > eventA_start = datetime.datetime.now()
> >
> > The problem is, I don't know the "A" part...the user could choose 
> > eventPotato or eventDinosaur.  I won't know in advance.  I want the 
> > name chosen/inputted by the user to be attached to the name for the 
> > time that event started.
> >
> > I have read that the way to do this properly in Python is with use of 
> > dictionaries, but I haven't found a reference online that shows how to 
> > do it is in a complete way.  Any help is appreciated.
> There are a multitude of different ways this can be accomplished with 
> dictionaries.  It really depends on what structure you want your data to 
> follow.
> By way of example, suppose we want to store the start time and length of 
> timers from the user.
> We could have an input loop as such:
> import time
> eventData = {}
> while True:
> name, duration = raw_input("Name your event (done to exit): "), 
> int(raw_input("How long should it last? "))
> if name.strip().lower() == "done":
> break
> 
> now we want to add the user's data to our dictionary so we can keep 
> track of events.
> 
> eventData[name] = time.time() + duration
> 
> note that I used the time.time() function to get the current time and 
> just added duration to it,
> so every event now stores the ending time of the event (when we want to 
> trigger it, say)
> 
> given this time, we can generate a list of all events that have happened 
> in the past,
> using list comprehensions or by other methods:
> [a for a in eventData.keys() if eventData[a] < time.time()]
> 
> then we can simply print out all events that have already occurred at 
> any point in time:
> while True:
> finished = [a for a in eventData.keys() if eventData[a] < time.time()]
> print "The following events have occurred: "
> for name in finished:
> print name
> time.sleep(1)
> if len(finished) == len(eventData.keys()):
> break
> 
> Of course this is by no means an ideal solution, it merely serves as an 
> example.
> 
> Does this make sense, and do you understand why it's better to use 
> dictionaries than to use variables
> to achieve this?
> [note - no code was tested, not guaranteed to work :)]
> -Luke

Thanks, yes, I am getting clearer by the minute in my understanding of 
dictionaries and why they are better than variables for these cases.  Although 
I was not familiar with what you can do with a list such as you did here:
> [a for a in eventData.keys() if eventData[a] < time.time()]
I think it basically makes sense.  I guess .keys() is a built-in method for 
dictionaries to return a list of all their values, then?  By the way, what was 
the purpose of the line with
time.sleep(1)
But otherwise, it seems a good start.  Thank you, and I'll try more of it 
tomorrow.


_
Don't get caught with egg on your face. Play Chicktionary!
http://club.live.com/chicktionary.aspx?icid=chick_wlhmtextlink1_dec___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Py2Exe Tutorial

2007-12-24 Thread Che M

> From: [EMAIL PROTECTED]> To: tutor@python.org> Date: Sun, 23 Dec 2007 
> 14:48:54 -0500> Subject: [Tutor] Py2Exe Tutorial> > > I am wondering if there 
> is a good tutorial on Py2Exe and its functions?> I have not been able to find 
> one. I have samples but that is not good> enough. It would be nice to have 
> something explain all the functions for> including directories, modules and 
> all that stuff when making an executable.> 
You might want to try using Andrea Gavana's GUI2Exe program, which allows using 
py2exe via a GUI interface.  It's here:  
http://xoomer.alice.it/infinity77/main/GUI2Exe.html
 
 
_
The best games are on Xbox 360.  Click here for a special offer on an Xbox 360 
Console.
http://www.xbox.com/en-US/hardware/wheretobuy/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] storing text in databases

2007-02-22 Thread Che M
Thank you Bob and Alan.  That helps alot.  I will store text as
files and index them somehow in the database (and yes Alan's
section on SQL on his site is a great resource for this).  -Che

_
The average US Credit Score is 675. The cost to see yours: $0 by Experian. 
http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE

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


[Tutor] basic plotting questions (pyplot vs matplotlib, etc)

2007-03-04 Thread Che M
I'd like to learn to use basic plotting in a wxPython GUI app,
with plots embedded in the GUI.  Some questions about this:

1) Of pyplot or matplotlib, which might you recommend?  My needs are:

- embedded plots in GUI (either can AFAIK)
- basic point/line/pie/bar graphs, regression lines, clickable points. (not 
sure if pyplot does regression
  lines or pie charts.)
- get the datapoints from a SQLite database queries
- reasonably do-able for a determined beginner programmer (me)
- not too memory intensive/app-bloating

Clearly matplotlib can do it all but I'm unsure if it is overkill for my 
needs?

2) What does "DC" mean?  As in wxDC?

3) I'd like to try a simple embedded plot in pyplot to get started.  Boa 
Constructor will place
a plot canvas to start, but I'm having trouble wading through the code of 
the pyplot example
from the wxPython demo.  Could someone help me with the barest bones of a 
simple line
plot on a canvas?  Just x = (1,2,3,4,5), y = (2,4,6,8,10) sort of thing.

TIA,
Che

_
Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month. 
Intro*Terms  
https://www2.nextag.com/goto.jsp?product=10035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f6&disc=y&vers=743&s=4056&p=5117

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


[Tutor] basics of passing arguments to make a graph

2007-03-22 Thread Che M
Hi, this is some *really* beginner Python stuff, hope you folks could help 
me.


I've been trying to make basic plots (line graphs) using the pyplot module 
(wx.lib.plot) in wxPython.  So far, so good.  To start, I can use a class 
like this (adapted from a demo) to draw a pre-defined graph:


class PlotPanel(wx.lib.plot.PlotCanvas):
   def __init__(self, *args, **kwargs):
   wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs) 
#PlotCanvas on which I draw graph
   self.Draw(self._drawGraph())   
#draw it using the next function


   def _drawGraph(self):   #this 
function draws just this one specific graph
   points = [(1,1), (3,4), (5,7), (7,14)] #just four points 
for a simple little line graph

   m=[]
   m.append(wx.lib.plot.PolyLine(points))  #uses the 
points to make a line
   m.append(wx.lib.plot.PolyMarker(points))   #uses the 
points to place markers
   return wx.lib.plot.PlotGraphics(m, "Graph Title",  #return the 
whole graph with title, etc.

   "x axis", "y axis")

This makes a nice graph, but the problem is that doing it this way means I 
need a seperate class for every graph I would want to make.  Obviously not 
the way to do it.


What I want instead is a way to have a class that makes my graphs but which 
expects to be passed points from some other place, in my case, due to some 
user choice (in selecting data from a list or whatever).


I get the sense that the idea is to pass a list of points to the drawGraph 
function.  Is that right?  So far I've fooled with it but can't get it to 
work.  Mostly because I don't understand argument passing well at all (like 
the *args, **kwargs stuff is still mysterious to me).  I was hoping this 
could help touch on some good principles for how to do this type of argument 
passing generally.


Thank you,
Che

_
It’s tax season, make sure to follow these few simple tips 
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=HMMartagline


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


Re: [Tutor] passing arguments to a make a graph

2007-03-23 Thread Che M

Thank you, Alan.   I started by adding a method called addPoints() to my 
class as you recommend.  But now I don't know how to pass a list of points 
to the addPoints() method.  Here's the relevant code, adding in your 
suggestions:

class PlotPanel(wx.lib.plot.PlotCanvas):
def __init__(self, points=[], *args, **kwargs):
wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs)
self.points = points
self.Draw(self._drawGraph())
self.SetEnableDrag(True)
#self.SetEnableGrid(True)

def addPoints(self, points):
self.points += points

def _drawGraph(self):
m=[]
m.append(wx.lib.plot.PolyLine(self.points))
m.append(wx.lib.plot.PolyMarker(self.points))
return wx.lib.plot.PlotGraphics(m, "Title)",
"x axis", "")

#this button tells it to make a graph using "mypoints".

def OnGraphButton(self, event):
mypoints = [(3,4), (5,6)] #these to be used 
in the plot
PlotPanel.addPoints(PlotPanel,mypoints)
self.notebook1.AddPage(imageId=-1, page=PlotPanel(self.notebook1), 
select=True,
  text='Weight')


The error I get using it this way is:

TypeError:  unbound method addPoints() must be called with PlotPanel 
instance as first argument (got type instance instead)

I'm lost.  Also, what does "self.points += points" mean?  What is the += 
operator?

Thanks,
Che

_
Mortgage refinance is hot 1) Rates near 30-yr lows 2) Good credit get 
intro-rate 4.625%* 
https://www2.nextag.com/goto.jsp?product=10035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2a5f&s=4056&p=5117&disc=y&vers=743

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


Re: [Tutor] passing arguments to a make a graph

2007-03-23 Thread Che M


>Instead of using the class create an instance(aka object)
>
>self.plotPanel = PlotPanel(mypoints,self.notebook1)
>
>That creates an instance passing the mypoints list in
>to youir init method along with the notebook1 that you
>pass when you create an instance later (see below).

This worked great, thanks!  One question:  you mention that in this way it 
is passing in the mypoints list and also the notebook1.  What I am unclear 
is, why are you allowed to pass in the notebook?  If you look at the 
original class PlotPanel():

class PlotPanel(wx.lib.plot.PlotCanvas):
def __init__(self, points=[], *args, **kwargs):
wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs)
self.points = points

[some methods deleted]

...in the __init__ function, it has parameters for self, points, *args, and 
**kwargs.  But you are passing it the notebook1, so how does it know which 
"slot" of these four parameters notebook1 refers to?

>See my OOP topic for more on classes, objects etc.

I will look at it, and it should make even more sense given this example.

Gracias,
Che

_
The average US Credit Score is 675. The cost to see yours: $0 by Experian. 
http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE

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


[Tutor] passing arguments via an instance of a class

2007-04-03 Thread Che M
Hi.  Alan G helped me a week or two back with how to pass a list of points 
to a class which could use it to draw a graph..  Now I am doing it again, 
but with different code (based on an example of embedding a matplotlib plot 
in wxPython) and having trouble.


That same basic issue is:  I need to create an instance of a class and in so 
doing pass the class two lists of numbers to serve as points in the graph.  
However, I can't get it to work because in the various ways I've tried it, 
the class is either not expecting to be passed a list as an argument, or it 
is not providing the list to its draw() method so nothing is plotted.


My problem is I don't understand how to create the class such that it a) 
expects to be passed two lists, and b) hands those lists off to its draw() 
method to use in drawing the graph.  Relevant code and some errors I got 
provided below.


---
class PlotPanel(wx.Panel):

   def __init__(self,parent, xpoints=[], ypoints=[], id = -1, color = 
None,\

   dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
   wx.Panel.__init__(self, parent, id = id, style = style, **kwargs)
   self.figure = Figure(None, dpi)
   self.xpoints = xpoints
   self.ypoints = ypoints
  #the NoRepaintCanvas class code snipped out
   self.canvas = NoRepaintCanvas(self, -1, self.figure)
   self.SetColor(color)
   self.Bind(wx.EVT_IDLE, self._onIdle)
   self.Bind(wx.EVT_SIZE, self._onSize)
   self._resizeflag = True
   self._SetSize()

# ... various code snipped which determines plot, size, color, etc...

#This draw method is what does the work of drawing the points.

   def draw(self):
   if not hasattr(self, 'subplot'):
   self.subplot = self.figure.add_subplot(111)

#if the following two lines were not commented out, the graph works fine
#but the point is to have these passed in by a user choice, not just
#always these same points.

   #x = [1,2,3]
   #y = [5,10,15]

#this next just plots a red line using whatever x,y points given

   self.subplot.plot(x,y, '-r')

#This is now the button which is supposed to feed the PlotPanel
#the points it needs.  It is a method of the wxFrame (code not shown)

def OnButton1Button(self, event):
#these are the points I want to be plotted when I push this button
   xpoints=[2,4,6]
   ypoints=[10,20,30]
   self.weightplot = PlotPanel(self.notebook1,xpoints,ypoints)
   self.notebook1.AddPage(imageId=-1, page=self.weightplot,
   select=True, text='Test Plot')



As is, when I press that button I get this error:

Name Error:  global name xpoints is not defined.

Suggesting the draw() method never got passed the xpoints (or the ypoints) 
via the button press.
I think I'm not setting up either the PlotPanel's __init__ or the draw() 
method or something to be able to receive these x and y lists, but I've 
tried it a number of different ways and can't figure it out.


Any advice is appreciated.
-Che

_
MSN is giving away a trip to Vegas to see Elton John.  Enter to win today. 
http://msnconcertcontest.com?icid-nceltontagline


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


Re: [Tutor] passing arguments via an instance of a class

2007-04-04 Thread Che M


John Fouhy said:

Can you post the full error message (including stack trace and line
numbers) and the code for the last function in the stack trace?
(i.e. the code where the NameError occurs)


It is now working (so I won't post the code/errors unless you think it is 
useful for people to see), and the corrected code is shown below.


Alan Gauld said:


you could do:

x = self.xpoints
y = self.ypoints

Or just wait and use self.xpoints etc at the point of use.


Thank you, Alan.  My whole problem is not fully understanding the self (to 
paraphrase Socrates...) and making sure to specify it.  I did change this in 
this way.  Also...



#This is now the button which is supposed to feed the PlotPanel
#the points it needs.  It is a method of the wxFrame (code not shown)
>
>def OnButton1Button(self, event):
>#these are the points I want to be plotted when I push this button
>xpoints=[2,4,6]
>ypoints=[10,20,30]
>self.weightplot = PlotPanel(self.notebook1,xpoints,ypoints)

But this needs to use self to access the member values:

self.weightplot = 
PlotPanel(self.notebook1,self.xpoints,self.ypoints)


Doing it this way didn't work--it gave the error:

AttributeError: 'Frame1' object has no attribute 'xpoints'

because, I think, self in this case refers to the whole frame, and not 
PlotPanel (i.e. notebook1 is an attribute of the Frame but xpoints and 
ypoints are meant to be attributes of PlotPanel).  The button was an object 
under the whole wxFrame (not sure I mentioned that), so self referred to the 
frame, not the PlotPanel, I think.  But writing it this way:


 self.weightplot = PlotPanel(self.notebook1,xpoints,ypoints)

did work.  Which is the same situation as what you helped me with last week. 
 The difference in this case is that I was, wrongly, not telling draw() to 
plot self.xpoints (I was giving just xpoints) and the draw() method could 
not know which instance this is from.  Is that right?


To summarize (just to have this clear for myself and other beginners), these 
are the lines which mattered:


1. The init had to have the xpoints and ypoints lists included so it could 
"accept" the lists when needed:


   def __init__(self, parent, xpoints=[], ypoints=[], id = -1, color = 
None,\

   dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):

2. The x and y lists had to refer to self.xpoints and self.ypoints (or I 
could have done it the other

way Alan mentioned):

   x = self.xpoints
   y = self.ypoints

3. I had to have an instance of the PlotPanel which was passed the parent 
notebook and the lists:


   self.weightplot = PlotPanel(self.notebook1,xpoints,ypoints)

4. And then I just added this self.weightplot PlotPanel instance as a page 
to my notebook:


   self.notebook1.AddPage(imageId=-1, page=self.weightplot,
   select=True, text='Test Plot)

Thanks Alan for your help! and John for your offer to debug!--it's great to 
understand this better and to have this simple plot actually display, very 
encouraging.  I guess I really have to work on my "self" control.  :)


-Che

_
MSN is giving away a trip to Vegas to see Elton John.  Enter to win today. 
http://msnconcertcontest.com?icid-nceltontagline


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


Re: [Tutor] Interactive plots...

2008-03-29 Thread Che M


 
> I am thinking about writing a program which will involve, among other  
> things, displaying a plot of a series of numbers.  The idea is that  
> you could click on the points and move them to change the numbers.   
> Reverse-plotting, I suppose.  It need not be complex; the numbers  
> will all be zero or one, and it's only necessary to flip the bits, so  
> click-and-drag is seriously overkill.  Really it would be better to  
> just double-click on a point to switch it from one value to the other.
> 
> Can anyone point me in the right direction?  I have written some  
> programs in python before, including TKinter, but this new project is  
> beyond the point that I know where to even start looking.  :)
> 
> In case you care, the application is in functional brain imaging; the  
> brain scans generate a certain number of time points (say 500) and  
> then the motion of the subject is also calculated.  Standard practice  
> is to generate a "censor" file composed of zeros and ones, where zero  
> indicates that that time point had excessive motion and must be  
> disregarded.  I want to display a graph of the motion over time, and  
> allow quick and easy interactive editing of the censor time series in  
> visual parallel to the motion graph.  This would save a lot of time;  
> at present everyone does this in Excel, which being a horrible  
> Windows program can't be integrated into the predominantly UNIX-based  
> processing pipeline.  And in any case, it requires manually typing  
> all the zeros, looking back and forth between the graph of motion and  
> the list of numbers.
> 
> I have already written a program to algorithmically generate the  
> censor time series from the motion data, but it is absolutely  
> essential to be able to manually double-check and if necessary make  
> minor edits.  I'd like to be able to keep that functionality in  
> Python rather than sending everyone back to Excel...  if possible!
> 
> Thanks very much for any help.
> 
> --
> -dave-

Without knowing more, it seems that this is going to be a lot of work, but if 
it will be used for years, probably worth it.  For graphing:  in the wxPython 
widget toolkit there is a PyPlot widget which does plotting, or you could use 
Matplotlib, a Python plotting library (with similarities to Matlab) with lots 
of functions.  In either case you can catch mouse events on the plot and 
connect those events to changing the display of which parts of the motion graph 
are "censored" (might not be possible with PyPlot; definitely with Matplotlib). 
 That way you could censor (or uncensor) sections of the trace right on the 
graph, and the censor time series would be updated from that.  

I'd also say about Excel ("being a horrible  Windows program") that it is not 
horrible, unless you meant that all Windows-only programs were horrible by 
virtue of running on Windows?  Excel is a good program, in my opinion.  But if 
you want to keep it all under Linux and sort of all of a piece, I get that.  



_
How well do you know your celebrity gossip?
http://originals.msn.com/thebigdebate?ocid=T002MSN03N0707A___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] web programming tutorials?

2008-04-17 Thread Che M

[I thought I sent a similar msg to this list 2 days ago, but now I'm not sure 
it went through, so sorry if I've doubled]

Can someone point me to a start-from-dead-scratch tutorial about the basics of 
web programming?  I've been learning wxPython for GUI programming, but web 
programming (that is, making web applications) seems like another world 
entirely.  I'm aware of *names*--Django, Pylons, CherryPy, TurboGears, Zope, 
Webpy, etc.--but I have a poor sense of what all this means,  and so I am sort 
of 'pre-Python' in my understanding.  I've scanned the archives of this list, 
but so far haven't found pointers to tutorials that assume very little 
knowledge.  

I was kind of hoping Alan Gauld's project would be updated for the tempting but 
not yet existent section on web programming.  Any word on that, Alan?  In lieu 
of that, can anyone recommend books/online tutorials/words of advice?

Thanks,
Che


_
Pack up or back up–use SkyDrive to transfer files or keep extra copies. Learn 
how.
http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web programming tutorials?

2008-04-18 Thread Che M


Thank you, everyone, for all the responses!  I will wade through them and try 
to get some understanding and then will no doubt come back with some questions 
in some days.  Much appreciated.
-Che

_
More immediate than e-mail? Get instant access with Windows Live Messenger.
http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_Refresh_instantaccess_042008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] datetime syntax error for May 8th and 9th 2008??

2008-05-16 Thread Che M

Am I missing something?  Why does May 7th
and other dates work but I'm getting "invalid
token" for May 8th and 9th?  (I have not tested
many other dates of the year in this way) This 
is from a freshly begun IDLE session:

IDLE 1.2  
>>> import datetime
>>> datetime.datetime(2008,05,07)
datetime.datetime(2008, 5, 7, 0, 0)
>>> datetime.datetime(2008, 05, 08)
SyntaxError: invalid token
>>> datetime.datetime(2008, 05, 09)
SyntaxError: invalid token

Is this a glitch in the Matrix?

Che

_
E-mail for the greater good. Join the i’m Initiative from Microsoft.
http://im.live.com/Messenger/IM/Join/Default.aspx?source=EML_WL_ GreaterGood___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime syntax error for May 8th and 9th 2008??

2008-05-16 Thread Che M



From: [EMAIL PROTECTED]

To: tutor@python.org
Subject: datetime syntax error for May 8th and 9th 2008??
Date: Sat, 17 May 2008 00:09:03 -0400








Am I missing something?  Why does May 7th
and other dates work but I'm getting "invalid
token" for May 8th and 9th?  (I have not tested
many other dates of the year in this way) This 
is from a freshly begun IDLE session:

IDLE 1.2  
>>> import datetime
>>> datetime.datetime(2008,05,07)
datetime.datetime(2008, 5, 7, 0, 0)
>>> datetime.datetime(2008, 05, 08)
SyntaxError: invalid token
>>> datetime.datetime(2008, 05, 09)
SyntaxError: invalid token

After trying it a bit more, I see that writing it this way works:

>>> datetime.datetime(2008,05,8)
datetime.datetime(2008, 5, 8, 0, 0)

So, then, why can one not use -MM-DD with these two 
dates and must instead switch to -MM-D?  I have a feeling
the explanation will be interesting and somehow make sense,
though right now it seems odd.




_
Keep your kids safer online with Windows Live Family Safety.
http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL_Refresh_family_safety_052008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime syntax error for May 8th and 9th 2008??

2008-05-20 Thread Che M



> Date: Fri, 16 May 2008 23:38:42 -0700
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [Tutor] datetime syntax error for May 8th and 9th 2008??
> CC: tutor@python.org
> 
> On Fri, May 16, 2008 at 9:29 PM, John Fouhy <[EMAIL PROTECTED]> wrote:
> > On 17/05/2008, Che M <[EMAIL PROTECTED]> wrote:
> >> >>> datetime.datetime(2008, 05, 08)
> >> SyntaxError: invalid token
> >
> > It's simpler than that... Try this:
> >
> >>>> x = 08
> >  File "", line 1
> >x = 08
> > ^
> > SyntaxError: invalid token
> >>>> x = 010
> >>>> x
> > 8
> >
> > Basically, python interprets integer literals starting with 0 as octal
> > numbers.  It's an old convention from C (or earlier?).  It doesn't
> > affect strings, so int('010') == 10 (unless you use eval).
> 
> 
> che,
> 
> john is correct.  any leading zero (0) of an integer number will be
> translated as base 8 or octal, which counts by 8's:
> 
> 00, 01, 02, 03, 04, 05, 06, 07, 10 (decimal/base 10: 8*1+0=8),
> 11 (decimal: 8*1+1=9), 12 (decimal: 8*1+2=10), 13 (decimal 8+3=11),
> 14, 15, 16, 17 (decimal: 15), 20 (decimal: 8*2+0=16), 21 (decimal:
> 8*2+1=17), etc...
> 
> the problem with "08" is that because you're counting by 8s, a value
> of "08" is invalid because the digits "8" and "9" are not part of the
> octal "alphabet" or character set. that is why "07" works but not
> "08".
> 
> as an FYI, because of this confusion, starting with Python 3.0, octal
> numbers will require a lowercase "o" (in the same manner as
> hexadecimal/base 16 numbers require an "x") after leading 0, i.e.,
> 0o7, 0o16, etc.  (Oo8 is still an invalid octal number.)
> 
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Thank you, Wesley, that is helpful and interesting.  
Best regards,
Che

_
E-mail for the greater good. Join the i’m Initiative from Microsoft.
http://im.live.com/Messenger/IM/Join/Default.aspx?source=EML_WL_ GreaterGood___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] when is object relational mapping for Python warranted?

2008-06-10 Thread Che M

(tried to write a descriptive subject line)

I'm curious whether I should consider learning either SQLObject 
or SQLAlchemy, and whether my needs would be worth it.  I am
learning to use SQlite databases for fairly simple storage and later
search, and have only recently learned about object relational
mapping (ORM).  "Fairly simple" = 4-6 tables with no more than
2-10 fields each, 100-5,000 records, with queries doing basic LIKE 
and other matches, nothing fancy.

I'd like to hear opinions on when it is worth it to use these ORM tools
for a Python database application, that is, in terms of the complexity
of the database or queries or the application, or when basic Python 
and SQL is sufficient.  It's a personal preference, I'm sure, but I just 
wanted to get some opinions.  Also, if there is an opinion about either 
of these two ORMs in terms of learning curve, quality, etc.

Thanks,
Che


_
It’s easy to add contacts from Facebook and other social sites through Windows 
Live™ Messenger. Learn how.
https://www.invite2messenger.net/im/?source=TXT_EML_WLH_LearnHow___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wanting to learn

2008-06-11 Thread Che M


Hi Michael,

> Since my background is web, I want to learn Python and how it relates  
> to the web. I have been told that I need to learn and understand the  
> basics in "standard/general" Python before I move onto something like  
> "django" but really, how much Python do I need to know before I can  
> head down the web path?

That's hard to quantify, and I myself don't have that experience yet,
but from what I've been told, web programming in Python is not at all
an easy thing to get started with and so you wouldn't want lack of basic 
Python knowledge to hinder you, especially when you'll be dealing with
the ins and outs of the web framework, like Django.  And so I'd guess
you'd need to understand more than just the very basics of Python, but
not a great deal beyond that.  Trying to quantify it, there is probably a 
"top 50" (100?) ideas in programming that you should be familiar with, 
and so you'd want to learn how Python handles that top 50.  In many
ways Python is a great language to start with as it is very readable,
sensible, and compact compared to others, from what I hear.

For me, the most "aha!" thing to learn in programming was that you 
could name an action and that would then be a storage for the results 
of that action.  For example (from wxPython):

mytext = textControl.GetValue()

now mytext will refer to the text which was got from the GetValue() 
action that the textControl does.  I've mainly only encountered that
kind of thinking in programming.  Of course, there's also classes and
attributes and all sorts of stuff, but one thing at a time.

> Is Python a language a total beginner/tutorial reader like myself can  
> learn or do I need to take classes at a local college? Is their is  
> just too much to learn to do this on my own. 

I started learning Python on my own and although I am far from anything
like a Programmer, have been able to make some applications and
have fun with it.  I've been goofing around with it for just under two years
in my off time.  It's been 100% without classes.  Some books, but mainly
websites, trial and error, reading this and other lists, etc.  Without Google
this would have not happened, I'm sure.  It is amazing how Google can
turn up old forum posts which completely answer my confusion of the
moment.  Or if not, I've gotten great help on this and other lists.

> I am starting to get a bit over whelmed with all of the information I'm 
> finding.

That's not surprising, either.  The key is to tune most of it out at first, and
just pick a few good sources.  There are some very good online tutorials,
like...

Alan Gauld's Learn to Program (great for conceptual basics, and he is a master 
tutor on this list)
http://www.freenetpages.co.uk/hp/alan.gauld/

Frederik "eff-bot" Lundh's guide to the Standard Python Library (great for 
knowing what the Python standard library can do, which is so much of the power 
of the language) 
http://effbot.org/librarybook/

ShowMeDo has many excellent instructional webcasts and is very Python-centric.  
www.ShowMeDo.com

I find the official Python tutorial to be usually not very good for beginners 
to programming, though (it's more for those coming from another language I 
feel).
Back search this list's archives, too.  Lots of good info already stamped into 
the
internet.

> So, can anybody head me in the right direction with my endeavor?
> Since I am on an intel/Mac which IDE should I be using? Which one will  
> be robust enough to take me through my journey? I have started with  
> IDLE but I have been told that it is a bare bones IDE. So, if I need  
> to learn how to use a IDE, I want to learn one that I will not have to  
> discard as I become more familiar with the Python language.

I wouldn't worry about discarding IDLE just yet; sometimes it is better to
start simple, and I still fire up IDLE now and then for testing.  I like using 
Boa 
Constructor as an IDE but that's also because I do GUI programming.  I believe 
it 
works for Mac as well.  There are tons of IDEs and people will all have their
favorites.  

Best of luck, and take it little by little,
Che



_
Now you can invite friends from Facebook and other groups to join you on 
Windows Live™ Messenger. Add now.
https://www.invite2messenger.net/im/?source=TXT_EML_WLH_AddNow_Now___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] when is object relational mapping for Python warranted?

2008-06-18 Thread Che M

Thank you both to Tim Golden and Jeff Younker for your helpful
responses last week [see archive] about ORMs in Python/SQLite.  Very
helpful, and I'll get around to giving it a try one of these days...

Che

From: [EMAIL PROTECTED]
To: tutor@python.org
Subject: when is object relational mapping for Python warranted?
Date: Wed, 11 Jun 2008 02:23:13 -0400








(tried to write a descriptive subject line)

I'm curious whether I should consider learning either SQLObject 
or SQLAlchemy, and whether my needs would be worth it.  I am
learning to use SQlite databases for fairly simple storage and later
search, and have only recently learned about object relational
mapping (ORM).  "Fairly simple" = 4-6 tables with no more than
2-10 fields each, 100-5,000 records, with queries doing basic LIKE 
and other matches, nothing fancy.

I'd like to hear opinions on when it is worth it to use these ORM tools
for a Python database application, that is, in terms of the complexity
of the database or queries or the application, or when basic Python 
and SQL is sufficient.  It's a personal preference, I'm sure, but I just 
wanted to get some opinions.  Also, if there is an opinion about either 
of these two ORMs in terms of learning curve, quality, etc.

Thanks,
Che


It’s easy to add contacts from Facebook and other social sites through Windows 
Live™ Messenger. Learn How.

_
Need to know now? Get instant answers with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ways to sync databases with Python and SQLite?

2008-09-09 Thread Che M

Hi list,

I have been trying to create a small desktop application with Python
that uses a small SQLite database.  Recently I've got use of a 2nd computer 
(for my job) and have thought now about using the app on that one as well.  

I'd like to get ideas about how I could extend the application so that the 
databases on each computer could be kept "synchronized" (not sure that is 
the right term here); that is, each new change on either computer would 
be updated on the other computer(s), given a bit of help from the user.  

I know that, for example, the Chandler PIM has a "hub" that allows sync'ing 
across 
multiple computers (though I was surprised to see it is a 8 step process for 
the user:  
http://chandlerproject.org/Projects/GetStarted#Sync%20Chandler%20Desktop%20across%20Mul
 )

(I realize a good way to do all of this is entirely as a web service, but that 
is beyond
my abilities, and I am trying to just complete a desktop app before learning 
much of that)

So, if anyone has ideas on ways to do this with Python and Sqlite that are:
- fairly simple (I'm not a real programmer)
- not laborious for the user to do (so that they actually keep the two dbs in 
sync)
I'd love to hear about it.

Thanks,
Che


_
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ways to sync databases with Python and SQLite?

2008-09-10 Thread Che M



> > I'd like to get ideas about how I could extend the application so that the
> > databases on each computer could be kept "synchronized" (not sure that is
> > the right term here); that is, each new change on either computer would
> > be updated on the other computer(s), given a bit of help from the user.
> 
> Does it have to be SQLite? Many databases, but not SQLite, can run as
> a server. If both computers are on the same network, an easy way to
> keep them in sync would be for them both to share a single database.
> Both MySQL and PostgreSQL are free and work this way.

It doesn't have to be SQLite--that's just what I've been learning, and there
are things about it that strike me as good for my purposes.  But the app is
not intended to be used with a network.  What I am envisioning is
a personal application that one uses on one's home computer and work
computers, but in most cases they'd not be on the same network.  

As someone else suggested, I could just copy, via a flash drive, the most 
recently written-to SQLite database file to the other computer, but that seems 
likely to go wrong in that I or the user would inevitably, at some point, wind 
up 
erasing the whole database or copying the wrong direction, etc., and I don't 
want 
this  to require any user carefulness to maintain the two copies in sync.

> Web applications aren't necessarily that hard. For example you can get
> simple create/read/update/delete functionality pretty much for free
> with Django (in the admin and databrowse apps).
> http://www.djangobook.com/en/1.0/chapter06/
> http://www.djangoproject.com/documentation/databrowse/
> http://www.b-list.org/weblog/2007/nov/13/instant-sites/

I will look into that; thanks, Kent, for the references.

Che



_
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ways to sync databases with Python and SQLite?

2008-09-10 Thread Che M


> "Che M" <[EMAIL PROTECTED]> wrote in message
> 
> > I'd like to get ideas about how I could extend the application so 
> > that the
> > databases on each computer could be kept "synchronized"
> 
> How do you intend to get the two computers to talk?
> Basically for any kind of synch both com,puters need to
> be able to compare notes. So the first question is what
> do we mean by synching here. Will it be over a network
> (the internet?)? Is it via a memory stick file transfer?

Considering that I want to lower the bar for the user to as
low/lazy as possible--and not require them to remember to transfer
the files with a flash drive or whatever--I'd think through the 
internet would be the best.  As I replied to Kent's reply, the two 
computers would not be on a shared local network, though they 
both would have internet access.

> > So, if anyone has ideas on ways to do this with Python
> > and Sqlite that are:
> > - fairly simple (I'm not a real programmer)
> 
> If you are using Python and SQLite then I beg to differ :-)

I appreciate that, but I often feel like a fledgling photographer who
has use of a Hasselblad camera--great tools, not so great tool user!   :)
(but thanks to this list and others and patience...getting there...)

> The key here is to keep a rolling log of what has changed.
> It can be a simple text file - which can be transferred between
> PCs and used to synch or it could be a database table.
> You then read both synch logs and eliminate conflicts then
> apply the merged set of changes. (A lot easier said than done!)
> 
> You might want to try a dummy application with a single table
> and limited update opportunities to get the feel for this before
> trying it on the real data! And be sure to take copious backups
> while testing!

I will try something like this and then try to incorporate it with
Kent's suggestion of having a (reasonably?) simple way to access this log
file via a website using, maybe, Django.  Keep in mind, my database
will mainly be just adding about 1-10 rows a day, very little UPDATES
(editing already-present rows), and will only have about 3-4 tables,
10 fields and hundreds (or at most a few thousands) of rows.  It
is not a business application with a big and rapidly changing database,
and by definition only one change can happen at a time.

Thanks, Alan,
Che





_
See how Windows Mobile brings your life together—at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ways to sync databases with Python and SQLite?

2008-09-10 Thread Che M


> One way to work around this and still use SQLight is to put the database on a 
> shared drive.  SQLight does table locking, or is it file locking.  
> Anyways conflicts will be very minimal to non-existant with only two clients 
> as most operations will complete in microseconds.  The SQLight 
> website even says this is a fine practice. 


I could have the database on a flash drive.  I'd like to avoid that, though, 
because inevitably the user
(mostly me) will forget to bring the drive back and forth from computer to 
computer.  

> However synchronizing two separeatly running databases is a very hard task, 
> and is very very easy to get wrong.  

Well, when you say "seperately running"... In my case, it would be rare (or 
maybe never) that one would be writing
to one computer's copy of the database at the same time as the other computer 
was doing it on its own.  The app
would be logging things in real time on one computer.  Later, the other 
computer needs to get the update so it knows
what happened.  But the two copies of the database are accessed in a usually 
mutually exclusive way (although, yes,
I guess you could run both apps on both computers at the same time and then 
make things difficult).  

I get the sense that Alan's idea of a log file to tell each DB how to change to 
keep current would work.  What 
are the "very hard" aspects of that?  (I don't doubt there are some real 
difficulties).

> However if all that one does is read and does no updates or deletes then you 
> could just copy the database over to the 'client' user.


No, both DBs are going to be writing and updating.

Thanks, Chad.

Che

On Tue, Sep 9, 2008 at 6:56 PM, Che M <[EMAIL PROTECTED]> wrote:






Hi list,

I have been trying to create a small desktop application with Python
that uses a small SQLite database.  Recently I've got use of a 2nd computer 
(for my job) and have thought now about using the app on that one as well.  


I'd like to get ideas about how I could extend the application so that the 
databases on each computer could be kept "synchronized" (not sure that is 
the right term here); that is, each new change on either computer would 

be updated on the other computer(s), given a bit of help from the user.  

I know that, for example, the Chandler PIM has a "hub" that allows sync'ing 
across 
multiple computers (though I was surprised to see it is a 8 step process for 
the user:  

http://chandlerproject.org/Projects/GetStarted#Sync%20Chandler%20Desktop%20across%20Mul
 )

(I realize a good way to do all of this is entirely as a web service, but that 
is beyond

my abilities, and I am trying to just complete a desktop app before learning 
much of that)

So, if anyone has ideas on ways to do this with Python and Sqlite that are:
- fairly simple (I'm not a real programmer)

- not laborious for the user to do (so that they actually keep the two dbs in 
sync)
I'd love to hear about it.

Thanks,
Che


Stay up to date on your PC, the Web, and your mobile phone with Windows Live. 
See Now


___

Tutor maillist  -  Tutor@python.org

http://mail.python.org/mailman/listinfo/tutor





_
Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-15 Thread Che M

(struggling to make an informative subject line)

Hi, I have what is no-doubt a dumb problem, but I can't get past it...

Given a list of items, I want to loop through the list, use the item in a 
SELECT 
 statement to query an SQLite database, and use the returned data from a 
.fetchall() to add key/value pairs to a dictionary.  

My problem is that it is only working for the *first* item in my list.  Each 
successive item shows the result of the fetchall() to be nothing.  And yet
I know it matches the criteria in my SELECT statements, because I can
a) see it in the database, and b) if I re-order my list, the first one in the 
list always returns something and the others don't, even if that first one
didn't return something when it was not first in the list before.  

It's as if after the first iteration of the loop, the SELECTs are not working.
I know .fetchall() "clears" the cursor, but I would think that on the next
iteration it would hit a brand new SELECT query and re-stock the cursor.
But I'm getting nothing returned.

Here in the lines is my flawed loop (I want to get a list of codes and a list 
of dates):

#---
for style in self.style_list:

#Get the codes...
cur.execute('SELECT code FROM Codes WHERE code != "" AND Style= "' + style 
+ '" 
AND start >=' + '"' + self.start_datestring + '"' + 'AND start < "' + 
self.end_datestring + '"')
mycodes = [ str(row[0]) for row in cur.fetchall() ]

#Get the dates...
cur.execute('SELECT start FROM codes WHERE code != "" AND Style= "' + style 
+ '" 
AND start >=' + '"' + self.start_datestring + '"' + 'AND start < "' + 
self.end_datestring + '"')
mydates = [ str(row[0]) for row in cur.fetchall() ] #Gets a list of the the 
dates these took place

#Add the data to the dictionary...
self.style_data_dict[style] = [mydates, mycodes] 

#---


However, if, instead of looping, I just copy and paste everything inside the 
loop two times 
(while providing as hard-coded the style at the start of each copy of it), it 
does
return the data both times.  (Of course, that won't work in the real program, 
but does
show, again, the SELECT statements themselves are not flawed--I think.)

So, can anyone tell me what I am doing wrong in the loop?  I've stared at it 
too long
and I am just not seeing it.

Thank you,
Che

_
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Che M


> I'm quite willing to help on this, but it's just not quite
> clear enough what's happening. Can I suggest that you
> post a *really small, self-contained* example which demonstrates
> the problem you're having. You might actually realise what's
> wrong as you do that, or if not someone like me can just run
> the example and see what you mean and point things out.

> Your code is missing just too many things for me
> to work out which bit is doing what. (And it's a bit
> awkward because of the long lines).
> 
> Try posting something like this:
> 
> 
> import sqlite3
> 
> db = sqlite3.connect (":memory:")
> db.execute ("CREATE TABLE codes (code)")
> db.executemany ("INSERT INTO codes VALUES (?)", [(i,) for i in range (10)])
> 
> q = db.cursor ()
> for n_try in range (3):
>   q.execute ("SELECT * FROM codes WHERE code > ?", [n_try])
>   q.fetchall ()
> 
> q.close ()
> 
> 
> > 
> and say what you think should happen, and what does
> happen. Note that the entire code I've posted there
> can be dropped straight into an interpreter and run
> which makes it much easier for people who are willing
> to help to see what you're trying to do.
> 
> TJG
> 

I normally do try to include a small runnable sample, but in this
case it seemed too extricated into the rest of my code.  As it happens,
as I was fooling around with variations of your code sample, it reinforced
my feeling that nothing was wrong with my loop and SQL query as such,
and it was then I noticed that it was the *list* that was wrong.

When I built my list, I built it using a .split() from a textbox field of 
comma-separated words.  But, I had written:

self.style_list = swlf.style_value.split(',')

when I should have written it as:

self.style_list = swlf.style_value.split(', ')


and that missing whitespace caused my list entries to each have
one whitespace in front of all but the very first item in the list, and
so of course they didn't match the words in the database.  So that
was the problem--I had been fixating on the SQL queries and it was
an improper use of .split() earlier in the code.  I have a feeling this
isn't the first time someone has made this mistake.

Thank you for your help,
Che


_
See how Windows connects the people, information, and fun that are part of your 
life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Che M

> I can't see any obvious reasons for your problems, I'm afraid, but I
> do have a comment on your SQL: the sqlite module supports using ? to
> indicate parameters.  So you could rewrite your select statements as:
> 
> cur.execute("select code from codes where code != '' and style = ? and
> start >= ? and start < ?", (style, self.start_datestring,
> self.end_datestring))
> 
> which is much easier to read, and also not vulnerable to SQL injection.

I will definitely adopt that (and had previously in other cases...for some
reason here I hadn't).  Thanks.

> Secondly, any reason why you aren't getting both code and start in a
> single select statement?  i.e.
> 
> cur.execute("select code, start from codes where code != '' and style
> = ? and start >= ? and start < ?", (style, self.start_datestring,
> self.end_datestring))

The reason is merely lack of experience and because of how I was
using the fetchall() in one list comprehension to build each list...since 
I did this twice, I thought I needed to restock the cursor, since each   
.fetchall() depletes the cursor.  But of course, that's dumb--now I 
just get fetchall() once first and do two list comprehensions, like:

fetched_data = cur.fetchall()
mycodes = [ str(row[0] for row in fetched_data ]
mystyles = [ str(row[1] for row in fetched_data ]

Much better--thank you.

> (heck, you could select code, start, style form codes -- pull all the
> information you need in a single query, and skip the loop
> altogether..)

I think I need the loop because the style will be multiple styles and
I need to take the codes that go with each style, so I am querying
style by style, so to speak.

Thanks,
Che

_
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running & debugging in python interactive shell

2009-01-14 Thread Che M



> Date: Wed, 14 Jan 2009 16:44:11 -0800
> From: artie.z...@gmail.com
> To: tutor@python.org
> Subject: [Tutor] running & debugging in python interactive shell
> 
> Greetings.
> 
> I am attempting to search archives, however I thought it would be OK to
> ask while I search... thank you to those who responded to my previous
> inquiry. Your response was very helpful to me.
> 
> My environment is embedded so I have only a python interactive shell for
> running python scripts. Does anyone know of an article that describes
> best practices for running and debugging scripts inside the python
> shell? Of course, I use import directive to run my script for first run.
>  I am seeking techniques for invoking parts of script after initial
> import. I hope this makes sense to those persons reading. :)
> 
> Cheers,
> AZ

I'd like to add to this question and expand it:  can anyone point me to
a good resource on debugging *generally*?  Particularly using a debugger.
I have never learned any "right" way to debug my code, just sort of read 
off the errors generated and do what I can.  I use Boa Constructor, which 
has a built-in debugger, but I don't quite grok how best to use it (some of
that is lack of practice, some is lack of understanding), though I get the 
sense that they are more-or-less the same across IDEs.

I thought maybe there is an existing tutorial somewhere on how best to
make use of a debugger.

Thanks,
Che



_
Windows Live™: Keep your life in sync. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_allup_howitworks_012009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running & debugging in python interactive shel

2009-01-15 Thread Che M



Date: Thu, 15 Jan 2009 12:20:45 -0600
From: sri...@gmail.com
To: pine...@hotmail.com
Subject: Re: [Tutor] running & debugging in python interactive shel
CC: tutor@python.org

On Wed, Jan 14, 2009 at 8:18 PM, Che M  wrote:







>> I'd like to add to this question and expand it:  can anyone point me to
>> a good resource on debugging *generally*? 
> The first result on "Debugger tutorial" on google sent me to this:

> http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html 

> Though it's for a specific program, it seems to have some good general 
> purpose advice. 
> Personally, I've never had the need for a debugger (maybe because I'm not 
> writing complicated 
> enough programs) - a simple "print" statement (in the right spot) tends to 
> take care of all of my 
> debugging needs.

That page didn't strike me as very helpful for my case, but thanks
anyway.  I'll Google for it, too, but just wondered if any of the
tutors here had any recommendations.  I just checked Alan Gauld's
tutorial and I see it doesn't have a debugger section (completely
understandably, as this is sort of advanced).  

I also use print statements a fair bit.  I've just heard that using
a debugger is a very useful thing and I thought maybe someone would 
have some tips here or knew of a good Python-relevant tutorial about it.

Thanks,
Che


-Wayne



_
Windows Live™: Keep your life in sync. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] referring to subfolders

2009-01-16 Thread Che M

I have been using absolute paths in my programs, but
want to get out of the habit as I try to run them on
other computers.  I was surprised to find that this
type of reference didn't work:

path = '/subfolder/myfile.py'

But instead I did it this way and it works:

import os.path
self.currentdir = os.curdir
self.mysubfolder = os.path.join(self.currentdir, "subfolder")
path = self.mysubfolder + '/myfile.py'

Is this really the only way to do it,and so I have to import
os.path each time I have a case where I refer to a subdirectory?
It seems like something quick/built-in like the first way should 
work, or maybe I am misunderstanding something?

Thanks.

_
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] referring to subfolders

2009-01-16 Thread Che M




> Date: Fri, 16 Jan 2009 21:26:52 -0800
> From: st...@alchemy.com
> To: pine...@hotmail.com
> CC: tutor@python.org
> Subject: Re: [Tutor] referring to subfolders
>
> Che M wrote:
>> I have been using absolute paths in my programs, but
>> want to get out of the habit as I try to run them on
>> other computers. I was surprised to find that this
>> type of reference didn't work:
>>
>> path = '/subfolder/myfile.py'
>
> Pathnames are relative by default. So:
> 'myfile.py'
> would be the file myfile.py in the current directory.
> 'subfolder/myfile.py'
> would be myfile.py inside subfolder, which is below the current directory.
>
> It's the initial / character which makes it absolute, and start from the
> root directory.

Thanks--much simpler!


_
Windows Live™: Keep your life in sync. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_allup_howitworks_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] clipboard questions

2009-01-25 Thread Che M

I'm curious about how to interact with the contents of the clipboard 
effectively and have a couple of questions...

1) Is there one cross-platform way to read the clipboard, or does one
have to have a different way to do it for Win, Mac, and Linux?  (I have
seen some ways with the win32clipboard module, and so thought maybe one
has to do a similar thing for each platform).

2) I would like to be able to copy formatting (bold, italics, bullets, 
hyperlinks, etc.) into the clipboard and then have Python have access 
to the text content and its formatting in such a way that it could be 
pasted somewhere within a Python app with formatting preserved.  How 
can that be done?

Thanks for any suggestions or thoughts.
Che


_
Windows Live™ Hotmail®…more than just e-mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] clipboard questions

2009-01-26 Thread Che M




> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Mon, 26 Jan 2009 10:13:15 +
> Subject: Re: [Tutor] clipboard questions
>
>
> "Che M"  wrote
>
>> I'm curious about how to interact with the contents of the clipboard
>> effectively and have a couple of questions...
>>
>> 1) Is there one cross-platform way to read the clipboard,
>
> In a generic sense no. But if the cut n paste is within a single
> application then yes, you can use a cross platform GUI framework.
> That will work across OS versions. Where it gets messy is if you
> want to paste from the generic OS clipboard into your application
> and different frameworks vary in how well they handle that.

Ahh, yes, that's a problem, because I am interested in using the
clipboard for cross-application cut/copy/paste, in fact from/to my
apps to any apps on any platform.  (One to all; all to one).  

>> 2) I would like to be able to copy formatting (bold, italics,
>> bullets,
>> hyperlinks, etc.) into the clipboard and then have Python have
>> access
>> to the text content and its formatting
>
> Thats even more tricky because not all clipboards will capture
> formatting codes in their original form. Some require special
> commands/events. It may also depend on the application that
> you are copying from. For example consider a MacOS web
> browser. Do you want to copy the underlying HTML formatting
> tags? Or the display PDF codes which are used by the Aqua
> graphics system used by the browser to actually display the
> output?

I would like to copy whatever makes the most sense for that 
context, similarly to how Word can accept a lot of different
formatting one could copy from, say, the web, and have it show
up in a similar way in the document.  Bold, italics, colors,
underline, paragraph breaks, bullets, fonts, font-size, alignment,
etc., such that it looks the same in both windows.  Ideally,
images, too.

>> In other words your display mechanism will need to be able
> to display whatever the clipboard passes. And your applucatin
> will need to be able to extract the data from it (eg parse PDF
> or RTF etc)

Right.  OK.

> Cut n paste between apps is non trivial even on a single OS
> and within a single framework. But if you have mixed environments
> it can get really messy in my experience! If it's all within a single
> framework then its not so bad.

I thought that was probably the reality, and I find that too bad.
Easy inter-app communication is a great thing, and I can't help but 
wish there was some built-in module in Python to help with this (I know,
I know, I'm being greedy, there are already so many great modules!)
in this most complete way that I am hoping for.  There is, e.g., a
very nice rich text control in wxPython, but for a few years now it
has been bereft of rich text input/output, including cut/copy/paste
or open/save, and so it sort of isolates the widget from inter-use 
with Word or OpenOffice.org, AbiWord, etc., though it can save as 
HTML.  I don't know C++, so I feel I cannot be helpful on adding 
this (wanted) functionality to the wxWidget itself, but was wondering if, while
the actual widget was still waiting for that enhancement (which
may or may not ever come, it depends on if someone takes it on), I 
could maybe take a misguided scratch at making some kind of pure 
Python go-between that could read out the clipboard and paste it 
into the richtextctrl and tell the control how to handle the formatting, 
and then vice-versa.  

Maybe there is a way to start to do this with HTML at least; 
Phillip Piper made this code for that purpose, here:

http://code.activestate.com/recipes/474121/

Although I don't understand this statement by him, "It would be nice 
to have this as a data object in wxPython, but that
doesn't support 
the necessary clipboard system calls
(RegisterClipboardFormat is 
essential)."  What does he mean by necessary clipboard system calls?
Note, this will not of course copy Word formatting codes, so there is
no Word --> Python pasting, though he claims there is Python --> Word
pasting (of HTML I guess).

All this makes me think this is probably beyond what I can reasonably
accomplish at this point in my understanding.  

Thanks for the insight.
Che


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

_
Windows Live™: E-mail. Chat. Share. Get more ways to connect. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] any cons to using a module of functions?

2012-02-02 Thread Che M

I have a bunch of functions that do various utility-type tasks in an 
application (such as prettifying date strings, etc.), and they are used in many 
modules.  Much of the time, I have just been lazily copying and pasting the 
functions into whichever modules need them.  I realize that is very bad form 
and I should refactor, and so I am beginning to put these functions in their 
own module so that I can import the module and its functions when I need it; 
they will all be in one place and only only place.

My question is about resources.  Let's say I have the module, myUtils.py, and I 
import it into every other module that will need one or more of the functions 
within it.  Is this in any way costly in terms of memory?  (since each time I 
import myUtils.py I import *all* the functions, instead of in the cut&paste 
approach, where I just run the functions I need).

I'm fairly sure this is not at all an issue, but I just want to understand why 
it's not.  

Thanks.



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