Re: [Tutor] trouble installing library

2013-04-24 Thread Mark Lybrand
What tutorial are you using BTW?


On Wed, Apr 24, 2013 at 6:29 AM, eryksun  wrote:

> On Wed, Apr 24, 2013 at 8:51 AM, Lolo Lolo  wrote:
> > Thanks for the help guys
> >
> >>> Scripts\activate.bat is a relative path, assuming your current working
> >>> directory is that of the virtual environment.
> >
> > your suggestion work. Initially i was doing Scripts/activate or
> > Scripts/activate.bat. I guess it didnt like "/" and i didnt realise the
> > difference.
>
> Many Windows APIs accept slash and backslash interchangeably in paths,
> but the cmd shell uses slash for options (e.g. dir /a:d) and only
> permits backslash in paths.
>
> > python -c 'import googlemaps' or py -3 -c 'import googlemaps' i get this
> > error:
>
> Generally you wouldn't  use the py launcher in an active virtual
> environment.  The Scripts directory is prepended to the PATH, so just
> run "python".
>
> >   File "", line 1
> > 'import
> >   ^
> > SyntaxError: EOL while scanning string literal
> >
> > which i guess means my program didnt get up to trying to import the file
>
> Notice the single quote. The syntax error is because the command line
> was parsed like this:
>
> ['python', '-c', "'import", "googlemaps'"]
>
> The -c option expects the command to be in the subsequent argument. So
> it's as if you had a script with just the following in it:
>
> 'import
>
> Clearly that's a syntax error in the string literal. But you didn't
> want a string literal in the first place.
>
> The command line is split into arguments on spaces and tabs. You have
> to use quotes for any string you don't want split up.  While a POSIX
> shell uses both single and double quotes for this (single-quoted
> strings are treated more literally), Microsoft's C/C++ runtime only
> uses double quotes. So just change it to the following:
>
> python -c "import googlemaps"
>
> 
>
> Reference: Parsing C++ Command-Line Arguments
> http://msdn.microsoft.com/en-us/library/17w5ykft%28v=vs.100%29
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


[Tutor] Random Python Tip

2013-03-15 Thread Mark Lybrand
I seem to remember a web page that generated a random Python programming
tip.  However my Google Fu is weak today.  Does anyone recall the URL of
what I am talking about?

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


Re: [Tutor] Bar Operator ??

2013-03-11 Thread Mark Lybrand
Thanks.  I think I kind of get it.  It probably will take a while for the
nuances of the filter to sink. Some things are filters that don't seem like
they should be, but that seems like my problem.

Mark :)


On Sun, Mar 10, 2013 at 11:33 PM, Danny Yoo  wrote:

> >
> > It's a filter:
> >
> > https://docs.djangoproject.com/en/1.5/ref/templates/builtins/
>
> And to be explicit about Mitya's point: it's technically not Python.
> It's part of Django's template language.  If it were Python, it'd be
> interpreted as the "or" bitwise operator,
>
>
> http://docs.python.org/3/reference/expressions.html#binary-bitwise-operations
>
> but that's definitely not what's happening here.  In your context, as
> part of a Django template document, interpret "|" as notation for the
> filtering operation.
>



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


[Tutor] Bar Operator ??

2013-03-09 Thread Mark Lybrand
I am working through the Django tutorial and I have come across some syntax
I am unfamiliar with.  From the context it makes perfect sense what it
does, but I haven't seen it before and was wondering if it is documented
anywhere (BTW I see other examples in the Django documentation, like date
formatting for example).

So what is this "|pluralize" syntax? Thanks in andvance

{{ poll.question }}
{% for choice in poll.choice_set.all %}
{{ choice.choice_text }} -- {{ choice.votes }} vote{{
choice.votes|pluralize }}{% endfor %}
Vote again?


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


Re: [Tutor] Teaching an 8-year-old programming.

2012-05-20 Thread Mark Lybrand
Have you considered this book:

http://www.amazon.com/Hello-World-Computer-Programming-Beginners/dp/1933988495

Mark

On Sun, May 20, 2012 at 2:41 PM, boB Stepp  wrote:
> On Sun, May 20, 2012 at 4:15 PM, Devin Jeanpierre
>  wrote:
>> I've heard remarkable things about http://www.programbydesign.org/ ,
>> but it's aimed at students a little older. Its design might help you;
>> although, it also probably depends on motivation / what you want to
>> teach.
>>
>> Anyway, that's the best I can offer. Good luck! It sounds like you're
>> in for a fun time. :)
>>
>> -- Devin
>
> Thanks for the link. It looks interesting, but I'm not sure it is the
> way to go currently for my son. However, it gives me some ideas for my
> wife's class, which covers 7th through 9th grades in a single
> classroom.
>
> There seem to be many, ... , many thoughts on how to best teach
> programming to kids!
>
> I am currently thinking about "Invent Your Own Computer Games with
> Python" by Al Sweigart. His thought is to give kids complete, workable
> code for a real game and let them fool around with it. This might
> work! I did something similar starting out with my son using QBASIC,
> giving him a brief program that played music. He seemed to have quite
> a lot of fun fooling around with different permutations of the
> commands. Later, when I introduced him to some new commands, like
> generating random numbers, he combined a number guessing game with his
> self-composed musical theme.
>
> Has anyone experience using this book?
>
> --
> Cheers!
> boB
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



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


Re: [Tutor] want to chat with someone - phone, skype, or email

2012-01-02 Thread Mark Lybrand
On Jan 2, 2012 12:22 PM, "Tamar Osher"  wrote:
>
> Hi!  I have never before learned a programming language, and I started
learning Python a couple of days ago.  I am wondering: How does a person
make the leap from reading about Python to doing Python?

Not directly responding to the petition for chat opportunities, but to
making the leap.  What has helped me (started with python at the end of
november) was to find problems and apply python to them.  From a simple
password generator,to massage text files and databases.  Just last week my
colleagues asked me to give them some more info on python as one after
another problem gets solved. If you don't have an immediate problem make
one.  One final idea would be to google "python challenge". One problem
after another to complete a sort of scavenger hunt.

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


Re: [Tutor] ez_setup.py for Python3 64-bit on Vista

2011-12-31 Thread Mark Lybrand
I think I got it actually.  Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ez_setup.py for Python3 64-bit on Vista

2011-12-31 Thread Mark Lybrand
... you'll see the newly installed script.  Additionally you can then

> trivially also install "pip", by executing:
>
> easy_install pip
>
>
Does this triviality depend on where the pip files are that I wish to "easy
install"?  I would assume that the answer is "yes". In which case, if those
pip files are in my Download folder, will the easy install put them in the
right place or reference them from the Download folder?

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


[Tutor] ez_setup.py for Python3 64-bit on Vista

2011-12-31 Thread Mark Lybrand
I have found this script:

http://peak.telecommunity.com/dist/ez_setup.py

But I can see that this is Python 2.x  Is there a Python 3 version, or
should I be doing something else to install an .egg on my system?

Thanks in advance.

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


Re: [Tutor] TypeError in class destructor

2011-12-10 Thread Mark Lybrand
def __exit__(self, *args):


Thanks guys. This is the solution I implemented and it works great.

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


[Tutor] TypeError in class destructor

2011-12-10 Thread Mark Lybrand
I am working on the Files chapter of Dive into Python 3, and have
implemented the example script at the end of this message.  The first input
prints to the terminal as expected, the second value prints to the file as
expected.  Then the script tries to destroy in the class instance and bombs
with:

TypeError: __exit__() takes exactly 1 positional argument (4 given)
Exception ValueError: 'I/O operation on closed file.' in <_io.TextIOWrapper
name
='out.log' mode='w' encoding='utf-8'> ignored

and the final input is, naturally, never printed.

Is the example wrong, or is this something to do with how Windows handles
stdout that is causing this not to work as designed?  I am using Python 3.2
on Windows Vista Home Premium.

import sys

class RedirectStdoutTo:
  def __init__(self, out_new):
self.out_new = out_new

  def __enter__(self):
self.out_old = sys.stdout
sys.stdout = self.out_new

  def __exit__(self):
sys.stdout = self.out_old


print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file,
RedirectStdoutTo(a_file):
  print('B')
print('C')



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


[Tutor] Fwd: Python Saved the Day

2011-12-04 Thread Mark Lybrand
Forgot to include the list. Sorry.

-- Forwarded message --
From: Mark Lybrand 
Date: Sun, Dec 4, 2011 at 12:59 AM
Subject: Re: [Tutor] Python Saved the Day
To: wesley chun 


The quick process of trying out different ideas, first in IDLE and then in
script was a biggie. List comprehensions rocked.  RE of course (but I still
have some stuff to learn about the differences in Python as compared to
Perl 5).

I was using odbc module to connect to SQL first, but quickly moved to
pyodbc and was much happier.

The problem was an application that uses tables from two separate
databases.  The database server was moved, but the old one was not
disconnected.  Further, a hosts file forced one office to continue to
update the old server.  The tables (12 in total) were rife with foreign key
relationships that needed to be maintained.

Don't misunderstand. I am a total noob in Python.  And everything I wrote
are total hacks.  But it was fun, it was quick and it was accurate.

Oh. One thing that delighted me to no end.  I had a main script that I was
using for processing. But would have to make separate scripts for more
specific analysis of problems that would appear.  The ability to import my
main script and use the functions and constants I defined there was a
godsend.  Oh, and did I mention list comprehensions :)

Mark


On Sun, Dec 4, 2011 at 12:51 AM, wesley chun  wrote:

> Congrats! I love hearing stuff like this... keep them coming! I'm curious
> as to how Python was able to help you get your job done this time (without
> going into anything confidential naturally). What was it about the
> language? Or was it specific Python modules/packages you used for the
> analysis?
>
> Does anyone else have similar stories? (I think I may be biased as I use
> Python for everything, trouble or otherwise, so I can't tell the difference
> anymore!)
>
> cheers,
> -wesley
>
>
> On Sun, Dec 4, 2011 at 12:45 AM, Mark Lybrand  wrote:
>
>> No question.   Last weekend I buckled down and learned as much Python as
>> I could (just because I have had an interest to do so for a while).  When I
>> got to work on Monday, there was a serious database issue that needed
>> addressing.  As I was trying to assess the situation, I employed Python to
>> help me do my data analysis.  I was able to sort through all the issues,
>> develop a corrective action plan and verify its accuracy, all in Python.
>> Plan was successfully implemented at 6PM today and all is well again. It
>> was a good week.
>>
>> --
>> Mark :)
>
>
>
> --
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
> http://corepython.com
>
> wesley.chun : wescpy-gmail.com : @wescpy
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com
>



-- 
Mark :)



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


[Tutor] Python Saved the Day

2011-12-04 Thread Mark Lybrand
No question.   Last weekend I buckled down and learned as much Python as I
could (just because I have had an interest to do so for a while).  When I
got to work on Monday, there was a serious database issue that needed
addressing.  As I was trying to assess the situation, I employed Python to
help me do my data analysis.  I was able to sort through all the issues,
develop a corrective action plan and verify its accuracy, all in Python.
Plan was successfully implemented at 6PM today and all is well again. It
was a good week.

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


Re: [Tutor] Programming Collective Intelligence Study Group

2011-11-29 Thread Mark Lybrand
Before I launch in on my master scheme.  I have come across another couple
of interesting Machine Learning/Python books:

Mining the Social Web by Matthew Russell. O'Reilly ISBN-13: 978-1449388348

Machine Learning: An Algorithmic Perspective by Stephen Marsland. ISBN-13:
978-1420067187


Okay, this is what I am thinking of trying out:

1. I will read through a chapter and try to provide a write up of the
material with the algorithms. Hopefully enough that even those without the
book can follow the source code and our discussions.

2. This will be communicated to Twitter, Google+ (I will make a page) and
Google Groups (I will make a group)

3. I will put a Wiki on my website and give anyone who wants it edit access
(just contact me).  There we can store notes and links and general
resources, with the idea that it could be a good Python/Machine Learning/AI
resource for us and others.

I will try to get up an initial post in the next week our two and announce
it here to allow folks to hook in via their preferred media.

This post is being made at the Machine Learning forum and to the Python
Tutor mailing list.  If you think of anywhere else to get the word out,
just holler.  I am thinking maybe the AI reddit group, AIQUS and the forum
on the AI class site. Others?

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


Re: [Tutor] Treating lists as lists

2011-11-29 Thread Mark Lybrand
Thanks everyone. Right before quitting time my brain froze up :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Treating lists as lists

2011-11-29 Thread Mark Lybrand
I am pretty sure I saw this somewhere but now I can't.  Here's the problem:
list = ['hello', 'world']
template = '%s %s'
print template % list

But it appears that list is just one (list) when I want to treat it as two
(items).  I can do that right?  How, pretty please?

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


Re: [Tutor] Programming Collective Intelligence Study Group

2011-11-29 Thread Mark Lybrand
>
> What are the Machine Learning Class and the Programming Collective
> Intelligence book? Should I have heard of them before?
>
>
Sorry for being unclear.  Machine Learning Class is one of the free classes
offered online by Stanford.  http://www.ml-class.org  This one started in
October.  Another round to start in January.  I highly recommend it.

Programming Collective Intelligence is a book by Toby Segaran from O'Reilly
ISBN-13: 978-0596529321  It uses Python to apply machine learning
techniques to real life problems and looks like loads of fun.

The Natural Language Processing with Python book is freely available here:
http://www.nltk.org/book


>
> If it's Google+ or Facebook, count me out.
>
>
Well, that would only be one dimension of what I propose, so totally
avoidable if you are that averse.  You should be fine with the discussion
forum and reference site I propose, which would be independent of any
social networks.

 If I had any idea what you were talking about, other than "something to do
with Python", then I might be.

>
Hopefully, I have done something to clarify what I was talking about.  If
not, don't hesitate to express your concerns via the list or to me
personally, either by email or on Facebook (just kidding).

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


Re: [Tutor] Programming Collective Intelligence Study Group (Mark Lybrand)

2011-11-29 Thread Mark Lybrand
Sorry about that. The book is called Programming Collective Intelligence.
 It is from O'Reilly Press.  It is written by Toby Segaran. ISBN-13:
978-0596529321.
 There is a PDF on the web, if you google around, but it doesn't seem that
kosher to me, so you are on your own if you decide to go that route.

The other book that we are considering afterwards is Natural Language
Processing with Python. Also from O'Reilly.  Written by Steven Bird, et al.
The book is legally freely available on the web. See here:
http://www.nltk.org/book

I hope that helps.  I will try to make my postings specific enough to be
able to participate without the book.  And will try to point people to
information that might help.  But I am also a noob (to all of it, Python,
NLP, ML).  Man I miss my curly braces (although not as much as I thought I
would, since Python is making it real easy to love it)


On Tue, Nov 29, 2011 at 1:44 AM,  wrote:

> Hey Mark
>
> Id be very much interested in this. While I mostly lurk on the python
> mailing list and have only dabbled in a few quick scripts. Then I wouldnt
> mind getting deeper into via a collective group.
>
> This is the first I've heard of this, Im not sure if you've posted before
> but which book are you using?
>
> /Regards
> Tommy
> On Tue, 29 Nov 2011 10:18:25 +0100, tutor-requ...@python.org wrote:
> > Send Tutor mailing list submissions to
> >   tutor@python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >   http://mail.python.org/mailman/listinfo/tutor
> > or, via email, send a message with subject or body 'help' to
> >   tutor-requ...@python.org
> >
> > You can reach the person managing the list at
> >   tutor-ow...@python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Tutor digest..."
> >
> >
> > Today's Topics:
> >
> >    1. Re: How to handle try and except in this case (Mic)
> >2. Re: useful function or reinventing the wheel?? (Mark Lybrand)
> >3. Programming Collective Intelligence Study Group (Mark Lybrand)
> >4. Re: Do loop in Python (stm atoc)
> >5. Re: How to handle try and except in this case (Dave Angel)
> >
> >
> > --
> >
> > Message: 1
> > Date: Tue, 29 Nov 2011 09:37:28 +0100
> > From: "Mic" 
> > To: 
> > Subject: Re: [Tutor] How to handle try and except in this case
> > Message-ID: 
> > Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> >   reply-type=original
> >
> >
> > On 2011-11-27 17:58, Mic wrote:
> >>> Say that I want to try and open 10 files. If none of these exists, I
> >>> want
> >>> an
> >>> error
> >>> message to appear. But only if NONE of these files exists.
> >
> >>> I know how to handle this with one file. But I don't know how to do
> that
> >>> with more than one.
> >>> So the program should try and open all 10 files and if, and only if,
> >>> none
> >>> of the files exists I want en error message to appear.
> >
> >
> > [Andreas wrote]:
> >>Use a counter which increments with every existing file. After opening
> >>all files check if the counter is bigger than 0.
> >
> >>Or, if you need to know which files exist, use a list, append existing
> >>files to it and check at the end if it's not empty.
> >
> >>Do you need more help?
> >
> > Andreas,
> >
> >
> > Thanks for your answer. I am afraid I don't understand this:
> > "Use a counter which increments with every existing file. After opening
> > all files check if the counter is bigger than 0."
> >
> >
> > I thought I could co along those lines earlier
> >
> > try:
> > text_file=open("Hey","r") and text_file1=open("Hey","r")
> > except:
> > print("hi")
> >
> >
> > So that hi is printed only and only if both files aren't existing.
> >
> >
> > Thank you!
> >
> >
> >
> >
> >
> >
> >
> > --
> >
> > Message: 2
> > Date: Tue, 29 Nov 2011 00:37:40 -0800
> > From: Mark Lybrand 
> > To: d...@davea.name
> > Cc: tutor@python.org
> > Subject: Re: [Tutor] useful function or reinventing the wheel??
> > Message-ID:
> >bw5h3w3pcur0dctprbg--2...@mail.g

[Tutor] Programming Collective Intelligence Study Group

2011-11-29 Thread Mark Lybrand
Over on the Machine Learning Class, I mentioned the idea of setting up some
online resources to go through the Programming Collective Intelligence book
as a group. This would include a group or discussion board of some type,
maybe a Google+ or Facebook page, and a wiki.  Then we would set a pace and
work through the book.  Since it is in Python, I thought this group would
be interested.  Am I wrong?  If it works out pretty good, we will probably
continue with Natural Language Processing (also Python) after we finish.

So, what is the interest like here?  Let me know and I will give you guys a
heads up when I get everything all set up.

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


Re: [Tutor] useful function or reinventing the wheel??

2011-11-29 Thread Mark Lybrand
>
>
> You're welcome.  I'd look forward to seeing your rewrite, and whether it's
> really shorter and more straightforward.
>
> Another advantage is doing less disk I/O if you start by trying the
> requested directory directly, and only recursing to parents if you can't
> make the requested directory.
>
> I took a quick stab at it  (ask me later for mark.py)  and it wasn't as
> straightforward as I expected.  The main problem comes down to how to
> define the base case.  I think you might have the same problem also. You
> assume that you can safely go back to the mount point.  But if the path
> given is relative, you have to allow for that as well. Perhaps a call to
> os.path.abspath is in order.  I also think that ismount() might not be
> legal on Windows, if you care about that.
>
> Also, we have to worry about what happens when one of the directories
> cannot be made for reasons unrelated to the syntax of the string.  For
> example, the user might not have write permissions for one or more of the
> directories.  In fact, the user might not have read permissions either.
>
>
I am actually passing in the path already os.path.abspath-ed.  So, I should
probably move that into the function for better encapsulation.  I am on
Windows, so ismount is behaving correctly (I tested it in Idle before going
with that as my base case).  Since this will end up being a throw-away, I
will probably not worry too much about permissions and failures, but I can
appreciate the need for such checks, should I decide to keep this for more
widespread use.

Thanks again.  I will send my solution when I get a chance to get back to
it (gotta get myself ahead in machine learning before the weekend gets too
close :)

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


Re: [Tutor] useful function or reinventing the wheel??

2011-11-28 Thread Mark Lybrand
>
>
>>  I couldn't follow your code, but finally concluded that it's trying to
> create a directory, creating the directories parents also if they don't
> exist either.  It would be much simpler if written recursively, but there's
> no need.
>
> Check out os.makedirs(), and see if it meets your needs.   (that's
> makedirs() function, in the os module)
>
>
Okay, so I guess commenting is in order :)  "It was hard for me to write
it, so it should be hard for you to read it." comes to mind.

And I will probably try to write it recursively based on your suggestion,
even though long term, I will just make use of os.makedirs, since that was
what I was re-inventing.

thanks

>
>
> --
>
> DaveA
>
>


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


[Tutor] useful function or reinventing the wheel??

2011-11-28 Thread Mark Lybrand
I am a habitual wheel re-inventor, so it would not surprise me, but I made
this little function that I was kinda proud of (seeing that I have only
been learning python like a week now):

It just takes a directory and checks to see if all the directories,
sub-directories exist and creates them if they don't:

def insure_exists_dir(dir):
  grow_path = [dir]
  while not os.path.ismount(grow_path[0]):
part_tuple = os.path.split(grow_path[0])
grow_path.insert(0, part_tuple[0])

  del(grow_path[0])
  while grow_path:
if not os.path.exists(grow_path[0]):
  os.mkdir(grow_path[0])
del(grow_path[0])
  return(dir)


Opinions?  What should I really be using?

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


Re: [Tutor] Critique and Question

2011-11-28 Thread Mark Lybrand
Just so y'all know, I replaced all the urlopen, read, write, nonsense with
the following:

urllib.request.urlretrieve(url_root + this_file, os.path.join(file_root,
this_file))

and it's all good :)

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


Re: [Tutor] Critique and Question

2011-11-28 Thread Mark Lybrand
Sorry for not providing all the required info. I am running python 3.2 on
windows vista. I determined the files are double spaced by viewong them
(random sampling) in notepad++. Not double spaced on server by downloading
one in the browser. Can I use the 'Wu' flag when writing.  I might just be
'w'-ing. I will look when I get home.

Thanks

Mark

Also a little bummed that subprocess module doesn't appear to work on
windows. I probably (hopefully) won't need it, but it still bums me.
 On Nov 28, 2011 4:27 AM, "Dave Angel"  wrote:

> On 11/28/2011 04:28 AM, Mark Lybrand wrote:
>
>> Okay, so I just started to learn Python.  I have been working through Dive
>> Into Python 3 and the Google stuff (great exercises IMHO, totally fun).
>>  However, with Dive, I had an issue with him referencing the files in the
>> example directory, which from the website seem very unhandy.  Although I
>> have since stumbled upon his GitHub, I made a Python script to grab those
>> files for me and it works great, with the exception of doubling the line
>> spacing.  So here is my code. I hope you critique the heck out of my and
>> that you point out what I did wrong to introduce double line-spacing.
>>  Thanks a bunch:
>>
>> import os
>> import urllib.request
>> import re
>>
>> url_root = 
>> 'http://diveintopython3.ep.io/**examples/<http://diveintopython3.ep.io/examples/>
>> '
>> file_root = os.path.join(os.path.**expanduser("~"), "diveintopython3",
>> "examples")
>>
>> main_page = urllib.request.urlopen(url_**root).read()
>> main_page = main_page.decode("utf-8")
>>
>> pattern = 'href="([^"].*?.)(py|xml)"'
>> matches = re.findall(pattern, main_page)
>> for my_tuple in matches:
>> this_file = my_tuple[0] + my_tuple[1]
>> data = urllib.request.urlopen(url_**root + this_file).read()
>> data = data.decode("utf-8")
>> with open(os.path.join(file_root, this_file), mode='w', encoding='utf-8')
>> as a_file:
>> a_file.write(data)
>>
>>  You don't tell what your environment is, nor how you decide that the
> file is double-spaced.  You also don't mention whether you're using Python
> 2.x or 3.x
>
> My guess is that you are using a Unix/Linux environment, and that the Dive
> author(s) used Windows.  And that your text editor is interpreting the
> cr/lf pair (hex 0d 0a) as two line-endings.  I believe emacs would have
> ignored the redundant cr.  Python likewise probably won't care, though I'm
> not positive about things like lines that continue across newline
> boundaries.
>
> You can figure out what is actually in the file by using repr() on bytes
> read from the file in binary mode.  Exactly how you do that will differ
> between Python 2.x and 3.x
>
> As for fixing it, you could either just use one of the dos2unix utilities
> kicking around (one's available on my Ubuntu from the Synaptic package
> manager), or you could make your utility manage it.  On a regular file
> open, there's a mode paramter that you can use "u", or better "ru" to say
> Universal.  It's intended to handle any of the three common line endings,
> and use a simple newline for all 3 cases.  I don't know whether urlopen()
> also has that option, but if not, you can always copy the file after you
> have it locally.
>
>
> --
>
> DaveA
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Critique and Question

2011-11-28 Thread Mark Lybrand
Okay, so I just started to learn Python.  I have been working through Dive
Into Python 3 and the Google stuff (great exercises IMHO, totally fun).
 However, with Dive, I had an issue with him referencing the files in the
example directory, which from the website seem very unhandy.  Although I
have since stumbled upon his GitHub, I made a Python script to grab those
files for me and it works great, with the exception of doubling the line
spacing.  So here is my code. I hope you critique the heck out of my and
that you point out what I did wrong to introduce double line-spacing.
 Thanks a bunch:

import os
import urllib.request
import re

url_root = 'http://diveintopython3.ep.io/examples/'
file_root = os.path.join(os.path.expanduser("~"), "diveintopython3",
"examples")

main_page = urllib.request.urlopen(url_root).read()
main_page = main_page.decode("utf-8")

pattern = 'href="([^"].*?.)(py|xml)"'
matches = re.findall(pattern, main_page)
for my_tuple in matches:
this_file = my_tuple[0] + my_tuple[1]
data = urllib.request.urlopen(url_root + this_file).read()
data = data.decode("utf-8")
with open(os.path.join(file_root, this_file), mode='w', encoding='utf-8')
as a_file:
a_file.write(data)

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


Re: [Tutor] Is there a way to add paths in Eric?

2011-11-20 Thread Mark Lybrand
Okay, I have answered my own question

import sys
sys.append()

Sorry for bothering.

Mark

On Sun, Nov 20, 2011 at 6:21 PM, Mark Lybrand  wrote:

> I am using Windows Vista.  I have some python scripts I have been
> developing in my learning folder.  Can I add the path to the folder in eric
> to call them interactively, or will I need to move them?
>
>
>
> --
> Mark :)
>



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


[Tutor] Is there a way to add paths in Eric?

2011-11-20 Thread Mark Lybrand
I am using Windows Vista.  I have some python scripts I have been
developing in my learning folder.  Can I add the path to the folder in eric
to call them interactively, or will I need to move them?



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


[Tutor] Fwd: Re: The Perennial 3.2 vs 2.7

2011-11-19 Thread Mark Lybrand
Whoops. Hit reply only again. Sorry terry.
-- Forwarded message --
From: "Mark Lybrand" 
Date: Nov 19, 2011 11:02 AM
Subject: Re: [Tutor] The Perennial 3.2 vs 2.7
To: "Terry Carroll" 

Based on what everyone has said and the fact that my learning material is
for 3, I think I will be okay learning 3 and will stumble into the gotchas
as I develop with 2.7. Luckily my experience as a programmer should keep me
warm at night :)

Mark

PS. I shall resist the temptation to force python to use curly braces and
will learn to embrace indentation.
On Nov 19, 2011 10:51 AM, "Terry Carroll"  wrote:

> On Thu, 17 Nov 2011, Wayne Werner wrote:
>
>  On Thu, Nov 17, 2011 at 8:45 PM, Mark Lybrand  wrote:
>>
>>  so, use my 2.7 and not my 3.2 for my study? Or use my 3.2 for
>>  study and then do what I have to in 2.7 after including those
>>  lines?
>>
>> Honestly it probably doesn't matter. Many 3rd party libraries have now
>> been ported to Python 3.x, so unless you have a particular library you're
>> interested in, I would start with 3.2 until you find something you can't do.
>>
>
> Personally, that's the biggy for me, and why I remain on 2.7.  wxPython
> has not yet been ported to Python 3, and that's a substantial big deal for
> me.
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] The Perennial 3.2 vs 2.7

2011-11-17 Thread Mark Lybrand
Okay, so I am about to take up the banner of learning Python again. I had
started with 3.2 and I have a book that I like.  But all of the things that
I want to use Python for appear to be 2.x specific.  Will I be setting
myself up for failure if I continue learning 3 and then try to write
programs in 2.x?  Note that I am an experienced programmer, albeit in
curly-brace languages (Perl, Java, C#, HTML/CSS/JavaScript), so that will
probably count in my favor.  But y'all would know better than I if there
are significant issues that I will need to overcome conceptually.

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


Re: [Tutor] Input

2011-09-30 Thread Mark Lybrand
There is apparently a livewires package that may be of someuse.
On Sep 30, 2011 1:25 PM, "Dave Angel"  wrote:
> On 09/30/2011 03:24 PM, Cameron Macleod wrote:
>> Hi,
>>
>> When you type
>>
>> Input("\n\nPress The Enter Key To Exit")
>>
>> it forces you to press the enter key to close the program. Why is it the
>> enter key instead of e.g. the 'esc' key?
>>
>>
>
> The input() function (not the Input()) function accepts a line of text
> from the user. That line is terminated by a newline, generated by the
> enter key.
>
> If you're trying to just wait for an "any-key", I don't know of any
> portable way to do it. There is a way in Windows, however.
>
>
>
> --
>
> DaveA
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor