Re: [Tutor] cannot get a label message to display immediately

2015-08-15 Thread Bill Allen
>
>
> On Sat, Aug 15, 2015 Bill Allen wrote:
>
> Yes, I see.  I will start working on reorganizing the code with that in
> mind.  One other thing that I have found that is quite interesting is that
> with my current code the use of after() works as expect with the message to
> the user showing up in the UI - if I run it through the IDLE editor.
> However, when I run the program from the command line or compile (package)
> the program with pyinstaller and run it as a standalone executable the
> message to the user does not show up in the UI!
>

Correction!  That was not what was happening.  Simple mistake in my code
was bypassing the call to the fuction with the after() statement and
running my main data processing routine directly.  I had forgot to bind
 to the routine with after() in it.   So, program worked OK when I
clicked the button but not when I hit Return!.  Dumb...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cannot get a label message to display immediately

2015-08-15 Thread Bill Allen
On Sat, Aug 15, 2015 at 2:21 AM, Alan Gauld 
wrote:
That works for getting the message printed but it still leaves
>
> the problem that your UI locks up during the long process.
> If its only for a couple of seconds it might be a mild hiccup
> but if your processing took, say 5s or longer, the user is
> likely to think the program is broken and may force kill
> the window or process or take similarly drastic action.
>
> That's why it's important to break the long process into
> chunks and call after() from within it. (or run it in the
> background) To do otherwise is to risk having your process
> cut short in mid flow with the data potentially only
> half processed - and you won't know which half!


Yes, I see.  I will start working on reorganizing the code with that in
mind.  One other thing that I have found that is quite interesting is that
with my current code the use of after() works as expect with the message to
the user showing up in the UI - if I run it through the IDLE editor.
However, when I run the program from the command line or compile (package)
the program with pyinstaller and run it as a standalone executable the
message to the user does not show up in the UI!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cannot get a label message to display immediately

2015-08-14 Thread Bill Allen
On Fri, Aug 14, 2015 at 3:06 PM, Alan Gauld 
wrote:

>
> That's the problem right there. You should never kick of an event handler
> that takes a long time to run. Either:
> 1) Kick of a separate thread to do the back end processing
> 2) break the function into short chunks and use a timer
> (after() in Tkinter) to repeatedly fire the function
> (this is the traditional GUI approach)
> 3) In Python 3.4 use asyncore to create an asynchronous event
> loop and feed the functions into that.
>
> ...
> def long_handler()
>update_status()# change the GUI
>getItem(data)  # fetch one item from data
>processItem(item)  # process one item,
>if data:   # is there any more?
>   after(20, long_handler)  # then go again after 20ms
>
>
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> Alan and everyone that responded,

Excellent information!  It was the concepts that I was falling short on an
this helped me a great deal.  In my particular situation, I found using the
after() method indeed worked just fine and was quite simple to implement.
In my case, as simple as this:

def processing(*args):   #my initial button click calls this
'''  display messages in the information message_frame while the data
is processed '''
info.set('PROCESSING, PLEASE WAIT...')   #the label message I was
wanting to get out there to the user
root.after(1000, process_part)  #the long running data process


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


[Tutor] cannot get a label message to display immediately

2015-08-14 Thread Bill Allen
I am working in Tkinter.   The scenario is that I click a button that
starts a function running.   No problem there.   However, the function may
take some time to run and I do not want the user to be worried.   I am
wanting to immediately set a label when the function starts to say "Please
Wait".  However, the label does not show up until the function completes.
How do I get both actions to happen essentially at the same time, the
writing of the label and the execution of the function?  I have no code to
show on this one because I am lost in the weeds, not sure of the general
way to go on this.


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


Re: [Tutor] lists, name semantics

2015-04-18 Thread Bill Allen
On Apr 18, 2015 4:11 PM, "boB Stepp"  wrote:
>
> On Sat, Apr 18, 2015 at 3:28 PM, Bill Allen  wrote:
> > On Apr 18, 2015 7:50 AM, "Peter Otten" <__pete...@web.de> wrote:
> >
> >> Bill Allen wrote:
> >>
> >> > Everyone that responded,
> >> >
> >> > Thanks very much for the excellent explanations!  The distinction
between
> >> > a reference to an object and a seperate copy of the object is quite
clear
> >> > now.
> >>
> >> You can test your newfound knowledge by predicting the output of the
> >> following script:
> >>
> >>
> >> a = [1, ["x", "y"], 3]
> >> b = a[:]
> >>
> >> a[1][1] = "hello!"
> >>
> >> print(a) # [1, ['x', 'hello!'], 3]
> >> print(b) # what will that print?
> >>
> >> Think twice before you answer. What is copied, what is referenced?
>
> > print(b) will print the original copy of a which b now references which
is
> > [1, ["x", "y"], 3]
>
> Uh, oh! You should have checked your work in the interpreter before
> replying! Peter is being very tricky!! (At least for me...) Look again
> at that list inside of a list and...
>
> boB
>
> P.S.: Watch out for top-posting. That tends to get peopled riled. I
> moved your response back into the normal flow of the interleaved

boB,

Ok, just tried it out.  In this example b=a and b=a[:] seem to yield the
same results even after the change to a, which I do not understand.  Should
not b be a copy of a and not reflect the change?

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


Re: [Tutor] lists, name semantics

2015-04-18 Thread Bill Allen
print(b) will print the original copy of a which b now references which is
[1, ["x", "y"], 3]
On Apr 18, 2015 7:50 AM, "Peter Otten" <__pete...@web.de> wrote:

> Bill Allen wrote:
>
> > Everyone that responded,
> >
> > Thanks very much for the excellent explanations!  The distinction between
> > a reference to an object and a seperate copy of the object is quite clear
> > now.
>
> You can test your newfound knowledge by predicting the output of the
> following script:
>
>
> a = [1, ["x", "y"], 3]
> b = a[:]
>
> a[1][1] = "hello!"
>
> print(a) # [1, ['x', 'hello!'], 3]
> print(b) # what will that print?
>
> Think twice before you answer. What is copied, what is referenced?
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lists, name semantics

2015-04-18 Thread Bill Allen
Everyone that responded,

Thanks very much for the excellent explanations!  The distinction between a
reference to an object and a seperate copy of the object is quite clear now.

--Bill
On Apr 18, 2015 1:44 AM, "Alan Gauld"  wrote:

> On 18/04/15 04:16, Bill Allen wrote:
>
>> If I have a list defined as my_list = ['a','b','c'], what is the is
>> differnce between refering to it as my_list or my_list[:]?   These seem
>> equivalent to me.  Is that the case?  Is there any nuance I am missing
>> here?   Situations where one form should be used as opposed to the other?
>>
>
> Others have already given some good explanations.
> I'll add a slightly different take.
>
> Your confusion starts with your first statement:
>
> > I have a list defined as my_list = ['a','b','c']
>
> What you should be saying is
>
> I have a list defined as ['a', 'b', 'c']
>
> Thats the list object that you are working with. The object is completely
> separate from the name that you choose to associate
> with it.
>
> You then bound that list to a name: my_list.
> You could bind it to any number of names but
> there would still only be one object:
>
> foo = my_list
> bar = foo
> baz = my_list
>
> Now I have 4 names all referring to the same list object.
>
> The next source of confusion comes from another mist-statement:
>
> > differnce between refering to it as my_list or my_list[:]
>
> The [:] at the end is an operator that returns a copy of the list.
> So when you use it you are NOT referring to the original list
> at all. You are creating a new copy.
>
> So if we now take one of our previous names, say foo, and do:
>
> foo = my_list[:]
>
> foo no longer refers to your original list ['a','b','c']
> but to a completely new copy of that list.
>
> If you modify my_list the changes will show up when you look
> at bar and baz as well. But foo will be unchanged
>
> my_list[0] = 'z'
> print baz   -> prints ['z','b','c'] - the same list as my_list
> print foo   -> prints ['a','b','c'] - a different list object
>
> Understanding the separation of names from objects in Python is essential
> to understanding how it works. It is different to many
> other languages in this respect.
>
> And understanding the difference between identity and value is also
> important. Two completely different objects can have the same value
> and so appear the same but they are in fact entirely different.
> Think about two drivers who both buy the exact same model of car.
> They may look identical, but they are two separate cars.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] lists, name semantics

2015-04-17 Thread Bill Allen
If I have a list defined as my_list = ['a','b','c'], what is the is
differnce between refering to it as my_list or my_list[:]?   These seem
equivalent to me.  Is that the case?  Is there any nuance I am missing
here?   Situations where one form should be used as opposed to the other?

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


[Tutor] cx_Oracle and Pyinstaller

2014-12-10 Thread Bill Allen
I have had success with producing a single file executable from a Python
script that includes cx_Oracle.  Here are the details.  Hopefully this will
also help someone struggling to get this working.


OS was Windows 7 Pro 64 bit.

Python was 2.7.8 32 bit.

cx_Oracle-5.13 for 2.7

PyInstaller-2.1

Python script oracle_connect.py, this was my program.

Oracle 11g instant client DLL files, OCI.dll and oraociei11.dll (OCI.dll
seems to stay constant from version to version of Oracle, but the other DLL
file's name will change with Oracle versions.)

A properly designed tnsnames.ora file.  This contains the necessary
connection information for your Oracle database.

A Pyinstaller-2.1 .spec file to make sure Pyinstaller did everything that
was needed to produce the single file .exe.  Pyinstaller-2.1 will not
automatically include both DLLs into the .exe without using a .spec file.
It does pick up the OCI.dll file automatically, but not oraociei11.dll.


First, I began by writing my Python script, which imports cx_Oracle, makes
the connection to the database, and does some work.  My working directory
was C:\Python27, so the script, two DLL files and .ora file were all placed
there.  Test the code to make sure that via the interpreter the script
interacted with the database correctly.


Second, I ran Pyinstaller-2.1 against the oracle_connect.py script without
the -F option (for single file .exe).  This created an oracle_connect.spec
file which I used as a template which was edited to include the needed
settings.


Third, I edited the oracle_connect.spec file (see bellow) to specify a
single file executable and to include the oraociei11.dll in the compilation
 The paths were specific to my installation environment and where I had
placed by Python source file and other files, adjust to match your
environment.  This oracle_connect.spec file I then placed in my
c:\Python27\PyInstaller-2.1 direcory.  Then I executed the following to
produce the single file executable.

C:\Python27\PyInstaller-2.1>..\python.exe .\pyinstaller.py
.\oracle_connect.spec


The resulting oracle_connect.exe may now be distributed without including
loose DLLs.  The only additional file needed is the tnsnames.ora file.
This cannot be compiled into the program and must reside in the same
location as the executable program.  It is a configuration file for the
communications parameters necessary to make the connection to the Oracle
database.  I include a sample of a tnsnames.ora file below.


oracle_connect.spec file contents:

# -*- mode: python -*-
a = Analysis(['..\\oracle_connect.py'],
 pathex=['C:\\Python27\\PyInstaller-2.1\\oracle_connect'],
 hiddenimports=[],
 hookspath=None,
 runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
  a.scripts,
  a.binaries  +
[('oraociei11.dll','c:\python27\oraociei11.dll','BINARY')],
  a.zipfiles,
  a.datas,
  name='oracle_connect.exe',
  debug=False,
  strip=None,
  upx=False,
  console=True )


Sample tnsnames.ora, values in <> are Oracle installation specific, contact
your local Oracle admin for the correct values to use.

# tnsnames.ora Network Configuration File

 =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = <1521>))
    )
(CONNECT_DATA =
  (SERVICE_NAME = )
)
  )




-- 


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


Re: [Tutor] question on self

2012-03-13 Thread Bill Allen
This little thread on the usage of self references when calling class instance 
methods and attributes was excellent, one of the best I have seen.

Thanks,
Bill Allen
Sent from my iPhone

On Mar 12, 2012, at 3:56, Alan Gauld  wrote:

> On 12/03/12 02:02, Michael Lewis wrote:
> 
>> I have another method called take turns (not shown for brevity
>> purposes). When I want to call it, why can't I just call it like a
>> function and use TakeTurns() instead of self.TakeTurns()?
> 
> The Steve's have given technical answers, its also stylistically
> better because it removed ambiguity for the reader as well as
> for Python.
> 
> Many corporate style guides advocate using this same style
> when using C++ or Java to make it explicit when you are using
> a class attribute rather than a local or global value/function.
> 
> It improves code clarity and therefore reduces potential bugs
> and speeds up maintenance for a tiny loss in initial coding
> productivity.
> 
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] list comprehension efficiency

2012-02-18 Thread Bill Allen
Generally speaking, are list comprehensions more efficient that the
equivalent for loop with interior conditionals for a given task?  Do they
compile down to the same Python byte code?

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


Re: [Tutor] Setting Up Emacs

2011-10-30 Thread Bill Allen
> > On 30/10/11 13:23, Rinu Boney wrote:
> > >I am New To Python.
> >
>
> > >I Would Like To Setup Emacs As A Python IDE.
> > >I Don't Know Anything About Emacs!
> >
>
> As others have also mentioned, try IDLE.  It comes packaged with Python
for Windows and is easily available for Python on Linux.   It will do most
of what you really, really need.

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


Re: [Tutor] [python-win32] Good Book

2011-07-25 Thread Bill Allen
>
> Dear All Pythonist,
>
>  I'm strarting learn python programming and I have been found many
> resources on it but I have a problem. I don't know, what is the best
> complete book for new learner like me.
>
>  I need your recommendation, thanks before . . .
>
>  Ryan,

Here some more good free book resources for Python programming,  by the same
author.  The website provides both HTML and PDF versions.

Book 1:  Intended for beginners and non-programmers (I think it is good,
even for programmers even if some material might be a little bit
elementary.  Certainly good if one has not programmed in a while, for
review.):
http://homepage.mac.com/s_lott/books/nonprogrammer.html#book-nonprogrammer

Book 2:  Intended for more experienced programmers:
http://homepage.mac.com/s_lott/books/python.html#book-python

Book 3:  Specifically focuses on OOP design, two editions of this book for
Python and Java:
http://homepage.mac.com/s_lott/books/oodesign.html#book-oodesign

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


Re: [Tutor] Alternate credentials

2011-05-04 Thread Bill Allen

On May 4, 2011, at 0:57, Tim Golden  wrote:

> On 04/05/2011 00:18, Alan Gauld wrote:
>> Since its more a Windows question than a Python one I suggest you try a
>> Windows forum. comp.python.windows might be worth a try? Or even the
>> ctypes group?
>> 
>> While we do have some Windows users here its not really a python nwewbie
>> type question.
> 
> 
> 
> Feel free to come back (or post to the python-win32 list) for more
> information
> 
> TJG

Tim, yes Alan is right about that.  I was unaware of the python-win32 group.  I 
think you have given me a good place to start on this and I really appreciate 
the help.  

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


Re: [Tutor] Alternate credentials

2011-05-03 Thread Bill Allen
I am running on MS Windows XP & Server 2003.


Sent from my iPhone

On May 3, 2011, at 12:02, Tim Golden  wrote:

> On 03/05/2011 5:35 PM, Bill Allen wrote:
>> I am needing to run a Python networked application with a specific
>> set of credentials, Windows AD, rather than the user's own so that
>> the app can access the needed CIFS shares.  Where should I start?
> 
> By saying what operating system you're running on, which will
> make quite a bit of difference to the answer.
> 
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Alternate credentials

2011-05-03 Thread Bill Allen
I am needing to run a Python networked application with a specific set of 
credentials, Windows AD, rather than the user's own so that the app can access 
the needed CIFS shares.  Where should I start?

--Bill

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


Re: [Tutor] os.rename vs. shutil.move

2011-04-16 Thread Bill Allen
Ok, thanks.

--Bill



On Sat, Apr 16, 2011 at 18:15, Steven D'Aprano  wrote:

> Bill Allen wrote:
>
>> What are the particular advantages or disadvantages concerning using
>> either
>> os.rename or shutil.move to rename a file.   I have tried both and for
>> simple renaming they seem equivalent.
>>
>
> Consider non-simple renaming.
>
> At the interactive interpreter, call:
>
> help(os.rename)
>
> and then
>
> help(shutil.move)
>
> to be enlightened.
>
> And read the Fine Manual:
>
> http://docs.python.org/library/shutil.html
>
> which conveniently now links directly to the source code, so you can see
> for yourself all the extra work shutil.move does to cover cases which
> os.rename may not cover (depending on the OS and/or file system).
>
> http://docs.python.org/library/os.html#os.rename
>
> os.rename is a thin wrapper around your file system's rename/mv command,
> with the same limitations as it has. shutil.move attempts to do extra work
> to overcome such limitations.
>
>
>
> --
> Steven
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.rename vs. shutil.move

2011-04-16 Thread Bill Allen
What are the particular advantages or disadvantages concerning using either
os.rename or shutil.move to rename a file.   I have tried both and for
simple renaming they seem equivalent.


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


Re: [Tutor] Python on TV

2011-04-14 Thread Bill Allen
On Thu, Apr 14, 2011 at 15:33, Luke Paireepinart wrote:

> I don't see how a content provider preventing you from accessing content
> internationally that they probably don't have international distribution
> rights to as censorship. It's not like your ISP is blocking your access.
>
>
Seriously, I was only joking!:-)

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


Re: [Tutor] how to develop a python exe file in windows using python3.1

2011-04-14 Thread Bill Allen
On Thu, Apr 14, 2011 at 08:42, ema francis  wrote:

> I am using python3.1 in windows environment.How can I create a python
> executable file?
> I tried with py2exe package but it is not compatible with python3.1.Isthere 
> any other way...
> pls help me...
>
>
cxfreeze works quite well for producing stand-alone Python apps.   The only
issue I have had is the occasional file or files from a third party module
that do not get automatically brought over into the distribution target
folder.   However, in all those cases the error messages when the program
was run gave me enough information to know what files I needed to go copy
from my Python folders over into the distribution folder so it could find
them.   I use cxfreeze regularly for situations that are best served with a
stand-alone Python program.   However, I do recommend carefully evaluating
if you need stand-alone or if installing the interpreter is more
appropriate.  I have found that not every program is best served by being
converted to stand-alone.

http://cx-freeze.sourceforge.net/


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


Re: [Tutor] Python on TV

2011-04-14 Thread Bill Allen
Same here.   I did not realize I was living in an internet censored country
here in Texas!



On Mon, Apr 11, 2011 at 16:04, bob gailer  wrote:

> On 4/11/2011 4:20 PM, Alan Gauld wrote:
>
>> I've just watched the Channel 5 programme "The Gadget Show"
>> where the presenters set a new Guinness world record for operating
>> the heaviest machine(*) using mind power. The software behind
>> this feat - was written in Python of course! :-)
>>
>> (*)The machine in question was a 50 ton industrial crane... used
>> to move a car from one end of a warehouse to the other.
>>
>> The show should be here - Pause at 1 minute 20 for the
>> Python screnshot:
>>
>>
>> http://fwd.channel5.com/gadget-show/videos/challenge/surprise-special-part-4
>>
>
> I am told "the video ... cannot be viewed from your currrent country ..."
>
> Sigh.
>
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Linux library for getch() and kbhit()?

2011-03-17 Thread Bill Allen
Alan,

Ah ha, ungetch(), that is what I was needing.   I had be trying to simulate
kbhit() with getch() and keep being left with unhandled data in the buffer.
I had resorted to a trash=raw_input() to clear it.


Many thanks,
Bill





On Thu, Mar 17, 2011 at 04:01, Alan Gauld  wrote:

>
> "Bill Allen"  wrote
>
>
>  I have found that for the Windows build of Python the msvcrt library
>> provides getch() and kbhit() functions.   Is there a library available for
>> the Linux Python build that provides the same or similar functions?
>>
>
> curses.
>
> Take a look at the event handling topic in my tutor for examples
> comparing msvcrt and curses.
>
> I'm not sure if curses provides a kbhit() equivalent but you can
> usually simulate the effect by using a combination of getch()
> and ungetch() - not pretty but it works.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Linux library for getch() and kbhit()?

2011-03-16 Thread Bill Allen
I have found that for the Windows build of Python the msvcrt library
provides getch() and kbhit() functions.   Is there a library available for
the Linux Python build that provides the same or similar functions?   I have
found lots of recipes out there to do these, but have not yet found a canned
library.  Being able to do a non-blocking character get or simply check for
a keyboard hit is so useful, so many times, that I wonder about there not
being something like the msvcrt library for Linux.  I am hoping there is and
I have just missed it somewhere.

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


Re: [Tutor] Resources

2011-03-12 Thread Bill Allen
These are quite good, The Building Skills Books, these are online.

http://homepage.mac.com/s_lott/books/index.html











Tarleton Area
Amateur Radio Club



On Fri, Mar 11, 2011 at 20:19, s s  wrote:

> Hello, I was wondering where I should go to improve my python skills.
> I have finished the official tutorial and the tutorials on the
> official python website.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] numpy import failure

2011-02-27 Thread Bill Allen
On Sat, Feb 26, 2011 at 22:45, Ezra Kahn  wrote:

> I am a total newb, learning to ween myself off of Matlab.  I am working off
> of EPD6.1, and I cannot get numpy to import.  Python keeps sending me back
> this:
>
> Traceback (most recent call last):
>  File "", line 1, in 
>import numpy
> ImportError: No module named numpy
>
> Ezra,

You did not mention that you installed the numpy package.   Numpy is not
included in the standard distribution of Python and may not be in other
distributions.   You likely need to install the numpy package first.
However, how and which numpy package to install depends on the answers to
the questions that Alan posed.

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


Re: [Tutor] python module to search a website

2011-02-26 Thread Bill Allen
n Sat, Feb 26, 2011 at 21:11, vineeth  wrote:

> Hello all,
>
> I am looking forward for a python module to search a website and extract
> the url.
>
> For example I found a module for Amazon with the name "amazonproduct", the
> api does the job of extracting the data based on the query it even parses
> the url data. I am looking some more similar query search python module for
> other websites like Amazon.
>
> Any help is appreciated.
>
> Thank You
> Vin
>
I am not sure what url you are trying to extract, or from where, but I can
give you an example of basic web scraping if that is your aim.

The following works for Python 2.x.

#This one module that gives you the needed methods to read the html from a
webpage
import urllib

#set a variable to the needed website
mypath = "http://some_website.com";

#read all the html data from the page into a variable and then parse through
it looking for urls
mylines = urllib.urlopen(mypath).readlines()
for item in mylines:
if "http://"; in item:
 ...do something with the url that was found in the page html...
 ...etc...


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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Bill Allen
Wow!   What an overwhelming response to my inquiry.   All the post have been
very informative and have given me plenty to consider.   I can see now this
is a win32 api question, not really Python.   There has been more than
enough here to point to some resources for win32 api and I have found
library resources for that for Python, so I think I am on my way.  It is
just a matter of finding the right win32 api calls to do what I am wanting
to do.


Thanks again everyone, this was a great help to me.


-Bill








On Wed, Feb 23, 2011 at 21:53, Bill Allen  wrote:

>
> I know that I can use the following to get a listing of the environment of
> my own system.   How can I do similar for another system on my network.
> This is for administrative purposes.
>
> >>> import os
> >>> for param in os.environ.keys():
> print(param, os.environ[param])
>
> --Bill
>
>
>
>
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
On Fri, Feb 25, 2011 at 22:39, Steve Willoughby  wrote:

>
> One question you need to figure out is how interactive you want this to be,
> or how automated.  That will drive the implementation of what comes after.
>  As will the list of available options at your site for securely allowing a
> remote host to run administrative tools on your windows systems.
>
>
> I am pretty basic and no-frills about programs, particularly ones that are
utilities for my own use.   I am one of those admins that has full
administrator privs on the site workstations, so I am able to run anything I
like on or against these systems.   I am envisioning a little command line
program that would work like this:

$python get_set_env.py -c some_computer_name
This would then just dump the system environment variables of
some_computer_name

$python get_set_env.py -c some_computer_name -e UG_SHOW_MOD True
On the system some_computer_name, this would edit the system environment
variable UG_SHOW_MOD to a value of True.

$python get_set_env.py -c some_computer_name -s UG_RUN_DIR  C:\UGII
On the system some_computer_name, this would create the system environment
variable UG_RUN_DIR and set it to the value C:\UGII

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


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
On Fri, Feb 25, 2011 at 21:33, Steve Willoughby  wrote:

> On 25-Feb-11 19:27, Steve Willoughby wrote:
>
>
> Or are you saying you want to, from a remote Unix system, reach out to a
> Windows system and see that Windows system's system environment variables?


Yes, that's it exactly.:-)

I administrate the workstations in our engineering environment and some of
the major pieces of software we use are configured via the Windows system
environment variables.  Being able to reach out to a PC and check or change
those is handy, even important, in my situation.   I am trying to explore
the possibility of managing these from a system I am using in a platform
independent way and figure that I ought to be able to do this with Python.
Perhaps there are third party Python modules I need to help accomplish this?

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


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
I apologize for not have been clear previously.   What I am trying to access
are the Windows system environment variables.   The same ones that are
listed out if you type the set command at a command prompt in Windows.


--Bill





On Fri, Feb 25, 2011 at 03:11, Alan Gauld  wrote:

>
> "Bill Allen"  wrote
>
>  I have times when it is useful for me to check the environment of a user
>> system on our lan remotely while trouble shooting and issue with them.
>>  Now,
>> this is quite easy to do while I am using a windows system via the
>> computer
>> management console.
>>
>
> I think we are meaning different things by "environment"?
> Can you give a specific example?
>
>
>  However, I am trying to do this via a linux workstation
>> (which is joined to the domain, etc.).   I cannot find a native
>> facility to duplicate the computer management functions, so I thought I
>> would write a program to fill the need.
>>
>
> Anything you can do locally you can do on the remote
> machine with a combination of ssh, rsh, rlogin, telnet etc.
> ssh is the safest but requires a bit more admin to set it
> up properly for maximum convenience.
>
> Having got remote access its just a case of figuring out
> which of the 500 or so Unix commands you need to
> use to do the job... :-)
>
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-24 Thread Bill Allen
I have times when it is useful for me to check the environment of a user
system on our lan remotely while trouble shooting and issue with them.  Now,
this is quite easy to do while I am using a windows system via the computer
management console.   However, I am trying to do this via a linux
workstation (which is joined to the domain, etc.).   I cannot find a native
facility to duplicate the computer management functions, so I thought I
would write a program to fill the need.   Not to mention, I thought it might
be a good learning opportunity.

--Bill








On Thu, Feb 24, 2011 at 03:00, Alan Gauld  wrote:

> "Bill Allen"  wrote
>
>
>  I know that I can use the following to get a listing of the environment of
>> my own system.   How can I do similar for another system on my network.
>> This is for administrative purposes.
>>
>
> Environments are user and process specific so you would need to
> access the remote machine, access the user account, connect
> to the specific process and then run the environment check.
>
> It rarely makes any sense unless its the user themselves
> doing the check.
>
> I assume there is a greater requirement at the bavk of this?
> What exactly is it you are trying to find out? There may be a better
> way.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] accessing another system's environment

2011-02-23 Thread Bill Allen
I know that I can use the following to get a listing of the environment of
my own system.   How can I do similar for another system on my network.
This is for administrative purposes.

>>> import os
>>> for param in os.environ.keys():
print(param, os.environ[param])

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


Re: [Tutor] creating classes while coding

2011-02-20 Thread Bill Allen
On Sun, Feb 20, 2011 at 19:59, Alan Gauld  wrote:

>
> "Bill Allen"  wrote
>
>
>  However, I do wonder a bit about the practice I have seen of some
>> Python programmers to implement relatively short bits of code, that would
>> be
>> quite simple using functions and procedural code, with classes.
>>
>
> OOP is often overkill, but if its the normal way of programming
> - and for many recent students its all they get taught - then using
> classes is the natural approach. "When all you have is a hammer
> everything looks like a nail..." However, there may be good reasons.
> Classes make reuse easier, in general, than functions. So if the
> task may become a building block for a future project, or even
> an extended version of the current one then building a class
> makes sense.
>

Thanks for the feedback.   Particularly when it comes to reuse of code, I
can see it could be worth my time to look into designing classes a bit more.
  I am starting to write enough code now that I am beginning to reuse some
bits of it regularly.  I have not yet taken the reuse of code further than
packaging up some functions into modules.  I'll look into this further.

You mentioned the programming methods being taught programming students
nowadays.   That OOP is a basic programming method being taught sure leaves
me in the dust.   The last formal programming class I took in college was
way back in the early 90s and it was to learn IBM 370 Assembly Language.
OOP was not only not on the radar, it was not even in the same solar
system!:-D

feeling kinda old, and I am not all that old...

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


Re: [Tutor] creating classes while coding

2011-02-20 Thread Bill Allen
That raises my next question.   Under what sort of programming circumstances
does it make sense?


--Bill








On Sun, Feb 20, 2011 at 19:01, R. Alan Monroe wrote:

> > I'll freely admit that I do not come from an OOP programming
> > background, so designing classes is not my first impulse when
> > writing code. Am I missing something?
>
> In my book, no, you're not missing something. I refer to it as
> "drinking the OO kool-aid". It's not compulsory. I just use it when it
> makes sense.
>
> Alan
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] creating classes while coding

2011-02-20 Thread Bill Allen
I know that Python not only supports OOP, but is fundamentally OOP in its
design.   Just in using the language and standard library, that much becomes
obvious.   However, I do wonder a bit about the practice I have seen of some
Python programmers to implement relatively short bits of code, that would be
quite simple using functions and procedural code, with classes.   Some such
code appears far more complicated than the job at hand really demands.   I
know there is not always a single right or wrong way of accomplishing
programming task, but why implement using classes unnecessarily?  When is it
necessary?  When is it best practice?  I'll freely admit that I do not come
from an OOP programming background, so designing classes is not my first
impulse when writing code.  Am I missing something?

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


Re: [Tutor] remote code execution

2011-02-15 Thread Bill Allen
If SAMBA is available on the Linux server, create a share and put your
source files there.  Then, map that CIFS share on you Windows workstation
and work on the files on the share with you local IDE.  Run the code via a
ssh or telnet connection session back to the Linux server.   Editing and
running would both be right on your desktop at that point.


--Bill








On Tue, Feb 15, 2011 at 12:50, S de Haan  wrote:

> Hi guys,
>
> I was wondering if there is a IDE or another environment that allows me to
> execute python code from my desktop computer on remote servers within my LAN
> without having to move the python files to and from the server.
>
> For instance, Im working on my local machine with Eclipse, but using the
> Interpreter that is on one of my Linux Servers.
>
> I hope i made my question clear enough.
>
>  Thanks, Sebas
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python printing to LPT

2011-02-12 Thread Bill Allen
As a followup, I have done some more searching and found some terrific
information on this subject of Python printing on the Windows platform.
The following link shows variations using some modules from the pywin32
package.

http://timgolden.me.uk/python/win32_how_do_i/print.html



--Bill






On Sat, Feb 12, 2011 at 15:34, ALAN GAULD  wrote:

> > to print some plain text to a dot matrix printer that the printer can
> handle
> > with its own internal fonts without need for any kind of other
> processing.
>
> In that case you can either open LPT1 as a file and write to it or use
> redirection to PRN from the command line.
>
>
> > I am dubious about the reliability of using the MS Windows "DOS" in
> > a production environment.
>
> We used DOS in production environments for 10 years before Windows
> took over, its not a problem for this kind of thing!
>
> Caveat: I've only tried his from Windows 98 but I don't know of any reason
> it shouldn't work from an XP CMD prompt. If
>
> echo "hello world" > PRN:
>
> works then it should work from Python too.
>
> HTH,
>
> Alan G.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python printing to LPT

2011-02-12 Thread Bill Allen
Ken,

Thanks for the great info on doing this on a Linux platform.  I am sure I
will be trying this with Linux sometime and I'll refer back to this.


--Bill










On Sat, Feb 12, 2011 at 18:33, Ken G.  wrote:

> On 02/12/2011 10:14 AM, Bill Allen wrote:
>
>>
>> Is is possible to print directly to an LPT port printer from Python?
>>
>>
>> --Bill
>>
>>  I use the following format in my Ubuntu 10.04 usage.  It set up a
> printing file.
>
>
> import os
>
># declare values
> month = "02"; date = "11"; year = "2011"
>
># open up file
> pr = os.popen("lpr", "w")
>
>#tab two times before printing string
> pr.write("\t\tDate of Drawing: "),
>
># print the month on the same line and added a space
> pr.write(month), pr.write (" " ),
>
># print the date on the same line and added a space
> pr.write(date), pr.write(" "),
>
># print the year on the same line and added a space
> pr.write(year), pr.write(" "),
>
># print up two line feeds
> pr.write("\n"), pr.write("\n")
>
># close the print file
> pr.close()
>
> will produce the following:
>
>Date of Drawing:  02 11 2011
>
> (start of new line here)
>
> Very time consuming and detailing but it work.
>
> Ken
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python printing to LPT

2011-02-12 Thread Bill Allen
Allan,

Ok, that encourages me to try it both ways and see which works out better.


Thanks,

--Bill









On Sat, Feb 12, 2011 at 15:34, ALAN GAULD  wrote:

> > to print some plain text to a dot matrix printer that the printer can
> handle
> > with its own internal fonts without need for any kind of other
> processing.
>
> In that case you can either open LPT1 as a file and write to it or use
> redirection to PRN from the command line.
>
>
> > I am dubious about the reliability of using the MS Windows "DOS" in
> > a production environment.
>
> We used DOS in production environments for 10 years before Windows
> took over, its not a problem for this kind of thing!
>
> Caveat: I've only tried his from Windows 98 but I don't know of any reason
> it shouldn't work from an XP CMD prompt. If
>
> echo "hello world" > PRN:
>
> works then it should work from Python too.
>
> HTH,
>
> Alan G.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python printing to LPT

2011-02-12 Thread Bill Allen
Alan,

Sorry for being vague.   I am wanting to print from a Python app that I am
writing for MS Windows XP.The desired end result is to print some plain
text to a dot matrix printer that the printer can handle with its own
internal fonts without need for any kind of other processing.What I
envisioned was something like a write method to a file, except LPT being the
file object.   I was hoping to do this directly from the Python program to
avoid calls to the Windows OS utilities, like a redirect to PRN, but am open
to that if I must.  If this was a *nix system of some sort, I would not
sweat it and use the OS to handle this but I am dubious about the
reliability of using the MS Windows "DOS" in a production environment.

Also, to answer the "what in the world are you doing with a dot matrix
printer?" question that some may be wondering.   Normally, I would not even
bother with an LPT dot matrix printer, but in this case the application
requires that the dot matrix printer do the job of printing to an "etching
tape".   The dot matrix pins cut through the wax on the etching tape
allowing it to be used as an acid electro-etching negative on metallic
parts.

I am guessing there may be a 3rd party module that allows for what I am
doing, but have not yet identified it.   As always, I am very open to any
suggestions and appreciative of the help.


--Bill



On Sat, Feb 12, 2011 at 13:06, Alan Gauld  wrote:

>
> "Bill Allen"  wrote
>
>
>  Is is possible to print directly to an LPT port printer from Python?
>>
>
> Yes.
>
> and No.
>
> It depends on how you define "directly" and what you are trying
> to print and from which OS.
>
> Alan G
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python printing to LPT

2011-02-12 Thread Bill Allen
Is is possible to print directly to an LPT port printer from Python?


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


Re: [Tutor] python packaging systems

2011-02-10 Thread Bill Allen
My main aim in packaging is simplicity of distribution to many workstations
at work.  Hiding the source is not an issue.   I have successfully used
cx_freeze.  I did find that in some cases I have had to manually copy some
files from my Python system, usually a 3rd party import, into the
distribution folder cx_freeze creates.   The error messages produced from
the code when run with missing files are mostly sufficient to work out what
files are missing.

Good information everyone.   Thanks very much.

--Bill









On Thu, Feb 10, 2011 at 12:21, ALAN GAULD  wrote:

> Yes, but a good installer will install Python (if needed)
> and then your app in one seamless operation from the
> users point of view. Then create the launch shortcut
> in the appropriate start menu.
>
> So the user only needs to click the launch icon to
> start the app, the fact that it's a Python scri[pt v a VB
> program versus a C++ native binary should be irrelevant
>
> to them.
>
>
> Alan Gauld
> Author of the Learn To Program website
> http://www.alan-g.me.uk/
>
>
>
>
> - Original Message 
> > From: Brett Ritter 
> > To: Alan Gauld 
> > Cc: tutor@python.org
> > Sent: Thursday, 10 February, 2011 17:26:37
> > Subject: Re: [Tutor] python packaging systems
> >
> > On Thu, Feb 10, 2011 at 11:14 AM, Alan Gauld 
> >wrote:
> > > Personally I don't like them and prefer to install a version of  Python
> > > and then install my modules separately.
> > >
> > > If you  want to hide your code(a little bit) you can ship only the  pyc
> > ...
> >
> > Don't forget that the motivation need not be  obfuscation.  I myself
> > like to package standalone programs for  non-techie friends and family
> > to use.  For them, "Run this" is a good  first instruction versus
> > "Install Python..." (regardless of how much their  lives might be
> > improved by the latter :) )
> >
> > --
> > Brett Ritter /  SwiftOne
> > swift...@swiftone.org
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python packaging systems

2011-02-09 Thread Bill Allen
I have found there are a few systems available to package Python programs as
standalone programs for distribution.   Do the folks here have any
recommendation or comment on any of these?

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


[Tutor] byte array conversion question

2011-02-02 Thread Bill Allen
I have found that there are a couple of ways to convert a byte array to a
string in Python.   Is there any advantage or disadvantage to either method?

my_bytes = b'this is a test'

str(my_bytes,'utf-8')   yields 'this is a test'
my_bytes.decode('utf-8';)   yeilds 'this is a test'


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


Re: [Tutor] ideas for a simple program

2011-01-25 Thread Bill Allen
For a simple programming project that probably has just enough complexity to
be interesting, google for Conway's Game of Life.   You'll find an algorithm
to use.

--Bill





On Tue, Jan 25, 2011 at 11:25, walter weston  wrote:

>
> can I have some good ideas for simple programs, I have come to realize the
> hardest part of programming is not having a project to do and having to
> think of one haha
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-25 Thread Bill Allen
That's exactly right!   Never heard it called that before, but that is
basically what happened.   I appreciate the help.

--Bill



On Tue, Jan 25, 2011 at 06:38, Wayne Werner  wrote:

> On Tue, Jan 25, 2011 at 1:42 AM, Alan Gauld wrote:
>
>>
>> "Bill Allen"  wrote
>>
>> Thats often the way :-)
>> The act of articulating the problem forces you to think about it
>> differently.
>>
>
> Also called "Rubber Duck Debugging"
> http://en.wikipedia.org/wiki/Rubber_duck_debugging
>
> <http://en.wikipedia.org/wiki/Rubber_duck_debugging>I've used it myself
> several times - usually in writing my message to the list (or on
> Stackoverflow.com) I end out answering my own darn question before I've
> finished typing it!
>
> -Wayne
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-25 Thread Bill Allen
Steven,

Thanks!   That is quite helpful to know the nuts and bolts of how that
works.

--Bill



On Tue, Jan 25, 2011 at 07:45, Steven D'Aprano  wrote:

> Bill Allen wrote:
>
>> Ok, I have definately verified this to myself.   The following works
>> perfectly and is a little easier to understand.  In this version, I am
>> plainly modifying my parts_list iterator thus producing the effect of an
>> iterator that is growing over the course of the operation of the code.
>>  So,
>> I am convinced that I had previously assigned part_list to out_list by
>> reference, not value as I mistaken thought when I first wrote the code,
>>
>
> I believe you're working under a misunderstanding there. Python is neither
> by reference nor value, if I've understood what you mean by that. (Normally
> people talk about "by reference" when discussing calling functions, not
> assignment, so I may have misunderstood you.)
>
> After executing the line `out_list = part_list`, *both* of these statements
> are *incorrect*:
>
> "out_list is a copy of part_list"  +++ WRONG +++
> "out_list and part_list are the same variable (out_list is an alias for
> part_list)"  +++ ALSO WRONG +++
>
> In a nutshell, Python uses the *name binding* assignment model. When you do
> this:
>
> part_list = [1, 2]
>
> Python creates a *name* "part_list" and binds it to the *object* [1, 2].
> Then when you do this:
>
> out_list = part_list
>
> the name "out_list" is created and bound to the same object as part_list.
> This means that out_list and part_list are two names for the same object,
> but this is not a permanent state of affairs -- they happen to be bound to
> the same object now, but you can re-bind one without changing the other.
>
> A month or so ago, somebody raised a similar question about pass by
> reference and pass by value. If you will excuse me blowing my own trumpet, I
> think my response then may be useful for you now:
>
> http://www.mail-archive.com/tutor%40python.org/msg46612.html
>
> To use a copy of part_list, you need to explicitly copy it. For lists, the
> easiest way is with a slice:
>
> out_list = part_list[:]
>
> You can also use the copy module, and functions copy.copy and
> copy.deepcopy, to copy other objects.
>
>
>
>  which explains it.  It was a silly mistake born from still being new in
>> Python and thinking in terms of another language I know that typically
>> assigns by value instead.  It had no occurred to me initially that it was
>> possible to modify an iterator in this way.  I do not think most languages
>> would allow this.
>>
>
> My understanding is that this behaviour -- multiple names for one object --
> is standard semantics for most modern languages, including Perl, Ruby, Java,
> and many others.
>
>
>
>
> --
> Steven
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
Ok, I have definately verified this to myself.   The following works
perfectly and is a little easier to understand.  In this version, I am
plainly modifying my parts_list iterator thus producing the effect of an
iterator that is growing over the course of the operation of the code.  So,
I am convinced that I had previously assigned part_list to out_list by
reference, not value as I mistaken thought when I first wrote the code,
which explains it.  It was a silly mistake born from still being new in
Python and thinking in terms of another language I know that typically
assigns by value instead.  It had no occurred to me initially that it was
possible to modify an iterator in this way.  I do not think most languages
would allow this.

Question, is it possible to copy values from one object to another in such a
way as they are not just references one to the other?

Sorry about asking questions and then answering them.  Things began to
become more clear with each question I asked.


def get_BOM(part_list):
x=re.compile('part='+'.*?'+'>')
BOM_List = []

pass_num = 0
for part_num in part_list:
mypath = "http://172.25.8.13/cgi-bin/search/part-url.cgi?part="; +
part_num
mylines = urllib.urlopen(mypath).readlines()
for item in mylines:
if "http://"; in item:
if "part=" in item:
xstring=str(x.findall(item)).strip('"[\'part=>\']"')
BOM_List.append(xstring)
for bom_item in BOM_List:
if bom_item not in part_list:
part_list.append(bom_item)
pass_num += 1
return(part_list)









On Tue, Jan 25, 2011 at 00:05, Bill Allen  wrote:

> By the way, my guess as to why this is working for me the way it does is
> that the statement
>
> out_list = part_list
>
> is actually linking these two objects, making them one.   My intention had
> been to just assign values from one to the other, but I think I have done
> far more than that.   In this case, if that is true, then it has worked out
> well for me, giving me a feedback loop through the data.  However, I can see
> that it could also be a pitfall if this behavior is not clearly understood.
> Am I right?   Am I way off base?  Either way, I could use some elaboration
> about it.
>
>
> --Bill
>
>
>
>
>
>
> On Mon, Jan 24, 2011 at 23:56, Bill Allen  wrote:
>
>> This is a bit embarrassing, but I have crafted a bit of code that does
>> EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
>> written a function to do a bit of webscraping by following links for a
>> project at work.  If I leave the code as is, it behaves like it is
>> recursively passing through the data tree- which is what I want.  However,
>> if I change it only slightly, it makes only one pass through the top level
>> data.  What I do not understand is why is ever behaves as if it is recursive
>> as the function is only called once.
>>
>> If I comment out_list=[] and let out_list-=part_list be used the following
>> parses through the whole tree of data as if recursive.  If I use out_list=[]
>> and comment out_list=part_list, it only processes to top level of the data
>> tree.
>>
>> The function is called only once as:  Exploded_BOM_List =
>> get_BOM(first_num)  in which I pass it a single part number to start with.
>> The webscraping bit goes to a particular webpage about that part where it
>> then picks up more part numbers and repeats the process.
>>
>> So can anyone help me understand why this actually works?  Certainly no
>> complaints here about it, but I would like to better understand why changes
>> the behavior so profoundly.  All the print statements are just to I could
>> follow out the data flow while working on this.  By following the data flow,
>> I am finding that part_list is actually having values added to it during the
>> time the function is running.   Problem is, I don't see clearly why that
>> should be so.
>>
>> def get_BOM(part_list):
>> x=re.compile('part='+'.*?'+'>')
>> BOM_List = []
>>
>> #out_list = []
>> out_list = part_list
>> print("called get_BOM")
>> pass_num = 0
>> for part_num in part_list:
>> mypath = "
>> http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part="; + part_num
>> mylines = urllib.urlopen(mypath).readlines()
>> print("pass number ", pass_num)
>> print(mypath)
>> print("PL:",part_lis

Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
By the way, my guess as to why this is working for me the way it does is
that the statement

out_list = part_list

is actually linking these two objects, making them one.   My intention had
been to just assign values from one to the other, but I think I have done
far more than that.   In this case, if that is true, then it has worked out
well for me, giving me a feedback loop through the data.  However, I can see
that it could also be a pitfall if this behavior is not clearly understood.
Am I right?   Am I way off base?  Either way, I could use some elaboration
about it.


--Bill





On Mon, Jan 24, 2011 at 23:56, Bill Allen  wrote:

> This is a bit embarrassing, but I have crafted a bit of code that does
> EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
> written a function to do a bit of webscraping by following links for a
> project at work.  If I leave the code as is, it behaves like it is
> recursively passing through the data tree- which is what I want.  However,
> if I change it only slightly, it makes only one pass through the top level
> data.  What I do not understand is why is ever behaves as if it is recursive
> as the function is only called once.
>
> If I comment out_list=[] and let out_list-=part_list be used the following
> parses through the whole tree of data as if recursive.  If I use out_list=[]
> and comment out_list=part_list, it only processes to top level of the data
> tree.
>
> The function is called only once as:  Exploded_BOM_List =
> get_BOM(first_num)  in which I pass it a single part number to start with.
> The webscraping bit goes to a particular webpage about that part where it
> then picks up more part numbers and repeats the process.
>
> So can anyone help me understand why this actually works?  Certainly no
> complaints here about it, but I would like to better understand why changes
> the behavior so profoundly.  All the print statements are just to I could
> follow out the data flow while working on this.  By following the data flow,
> I am finding that part_list is actually having values added to it during the
> time the function is running.   Problem is, I don't see clearly why that
> should be so.
>
> def get_BOM(part_list):
> x=re.compile('part='+'.*?'+'>')
> BOM_List = []
>
> #out_list = []
> out_list = part_list
> print("called get_BOM")
> pass_num = 0
> for part_num in part_list:
> mypath = "http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part=";
> + part_num
> mylines = urllib.urlopen(mypath).readlines()
> print("pass number ", pass_num)
> print(mypath)
> print("PL:",part_list)
> for item in mylines:
> if "http://"; in item:
> if "part=" in item:
> xstring=str(x.findall(item)).strip('"[\'part=>\']"')
> BOM_List.append(xstring)
> print("BL:",BOM_List)
> for bom_item in BOM_List:
> if bom_item not in out_list:
> out_list.append(bom_item)
> print("OL:",out_list)
> pass_num += 1
> return(out_list)
>
>
>
>
>
>
>
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
This is a bit embarrassing, but I have crafted a bit of code that does
EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
written a function to do a bit of webscraping by following links for a
project at work.  If I leave the code as is, it behaves like it is
recursively passing through the data tree- which is what I want.  However,
if I change it only slightly, it makes only one pass through the top level
data.  What I do not understand is why is ever behaves as if it is recursive
as the function is only called once.

If I comment out_list=[] and let out_list-=part_list be used the following
parses through the whole tree of data as if recursive.  If I use out_list=[]
and comment out_list=part_list, it only processes to top level of the data
tree.

The function is called only once as:  Exploded_BOM_List =
get_BOM(first_num)  in which I pass it a single part number to start with.
The webscraping bit goes to a particular webpage about that part where it
then picks up more part numbers and repeats the process.

So can anyone help me understand why this actually works?  Certainly no
complaints here about it, but I would like to better understand why changes
the behavior so profoundly.  All the print statements are just to I could
follow out the data flow while working on this.  By following the data flow,
I am finding that part_list is actually having values added to it during the
time the function is running.   Problem is, I don't see clearly why that
should be so.

def get_BOM(part_list):
x=re.compile('part='+'.*?'+'>')
BOM_List = []

#out_list = []
out_list = part_list
print("called get_BOM")
pass_num = 0
for part_num in part_list:
mypath = "http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part=";
+ part_num
mylines = urllib.urlopen(mypath).readlines()
print("pass number ", pass_num)
print(mypath)
print("PL:",part_list)
for item in mylines:
if "http://"; in item:
if "part=" in item:
xstring=str(x.findall(item)).strip('"[\'part=>\']"')
BOM_List.append(xstring)
print("BL:",BOM_List)
for bom_item in BOM_List:
if bom_item not in out_list:
out_list.append(bom_item)
print("OL:",out_list)
pass_num += 1
return(out_list)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] not understanding a recursion example

2011-01-21 Thread Bill Allen
Peter,

Thank you very much for the explanation.   I understand this much better
now.   You are correct, the implementation you show is easier for me to
understand.



--Bill









On Fri, Jan 21, 2011 at 03:43, Peter Otten <__pete...@web.de> wrote:

> Bill Allen wrote:
>
> > I am not understanding the following code (I did not write it).  It
> > demonstrates walking a tree-like data structure using recursion.  It does
> > run and produces reasonable output.  I particularly do not understand the
> > "traverse.level" statements.  Can anyone give me an idea how this is
> > working
> > and the principles?  I would like understand recursive calls in Python
> > better as I have not used the technique previously.
>
> > def traverse(data):
> > print(' ' * traverse.level + data['text'])
> > for kid in data['kids']:
> > traverse.level += 1
> > traverse(kid)
> > traverse.level -= 1
> >
> > if __name__ == '__main__':
> > traverse.level = 1
> > traverse(data)
>
>
> Functions are objects in python; you can tuck arbitrary attributes onto
> them, and the above uses a function attribute instead of a global variable.
> A more standard way to write the above would be
>
> def traverse(data):
>global level
>print(' ' * level + data['text'])
> for kid in data['kids']:
> level += 1
>traverse(kid)
> level -= 1
>
> if __name__ == '__main__':
> level = 1
>traverse(data)
>
> What it does:
> * call traverse with the outermost dictionary
> * print the data["text"] value indented by the current global level.
> * iterate over the data["kids"] list of dictionaries
> * for each entry in that list
>- increment indentation level
>- invoke traverse which will print the data["text"] value.
>  (Remember that traverse was called with the current value of kid, so
>   in terms of the outer traverse() the inner traverse() is printing
>   kid["text"]) Process the kid's kids in the same way.
>- decrement the indentation level
>
> However using global variables is generally a bad practice.
> It is easy to leave them in an inconsistent state, and if you are using
> multiple threads (i. e. invoke traverse() a second time while the first
> call
> hasn't finished) you'll end up with a big mess.
>
> I would therefore write the traverse function as
>
> def traverse(data, level):
>print(' ' * level + data['text'])
> for kid in data['kids']:
> traverse(kid, level+1)
>
> if __name__ == "__main__":
>traverse(data, 1)
>
> which I think may also be easier to understand.
>
> Peter
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] not understanding a recursion example

2011-01-20 Thread Bill Allen
I am not understanding the following code (I did not write it).  It
demonstrates walking a tree-like data structure using recursion.  It does
run and produces reasonable output.  I particularly do not understand the
"traverse.level" statements.  Can anyone give me an idea how this is working
and the principles?  I would like understand recursive calls in Python
better as I have not used the technique previously.

Thanks,
Bill


data = {'count': 2,
'text': '1',
'kids': [{'count': 3,
  'text': '1.1',
  'kids': [{'count': 1,
'text': '1.1.1',
'kids': [{'count':0,
  'text': '1.1.1.1',
  'kids': []}]},
   {'count': 0,
'text': '1.1.2',
'kids': [{'count':0,
  'text': '1.1.1.2',
  'kids': [{'count':0,
'text': '1.1.1.1.1',
'kids': []}]}]},
   {'count': 0,
'text': '1.1.3',
'kids': []}]},
 {'count': 0,
  'text': '1.2',
  'kids': []}]}

def traverse(data):
print(' ' * traverse.level + data['text'])
for kid in data['kids']:
traverse.level += 1
traverse(kid)
traverse.level -= 1

if __name__ == '__main__':
traverse.level = 1
traverse(data)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Python Script to read battery level

2011-01-17 Thread Bill Allen
Tim,

Thanks for posting this.   I have several uses for this WMI module at my
work.


--Bill






On Mon, Jan 17, 2011 at 04:07, Tim Golden  wrote:

> On 17/01/2011 03:01, FT wrote:
>
>> Is there a way to read the battery level using Python?
>>
>> I am totally blind and want to write a script to capture the battery
>> level and send it through the voice activeX so I can speak it...
>>
>
> WMI should be able to query the battery information:
>
> 
> import wmi
>
> c = wmi.WMI ()
> for battery in c.Win32_Battery ():
>  print battery.Caption, battery.EstimatedChargeRemaining
>
> 
>
> The pure-python wmi module is based here:
>
>  http://timgolden.me.uk/python/wmi/index.html
>
> and can be installed via easy_install / pip.
>
> Information on the attributes of the Win32_Battery class are
> available here:
>
>  http://msdn.microsoft.com/en-us/library/aa394074%28v=vs.85%29.aspx
>
>
> You might also be interested in the pyttsx project
> (successor to the Windows-specific pytts):
>
>  http://pypi.python.org/pypi/pyttsx/1.0
>
> although if you have existing code to work with an ActiveX
> control then I doubt it brings you any advantages.
>
> TJG
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-14 Thread Bill Allen
I will agree that it seems odd, but here is a sample run from my system.  I
promise I am not pulling anyone's leg!   :-))

wallenpb@Ubuntu-D810:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello world")
hello world
>>> x = input("how many?")
how many?5
>>> x
5
>>>


On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson  wrote:

> On 01/13/2011 10:29 PM, Bill Allen wrote:
> > That is correct about the difference between Python 2 and Python 3
> > syntax.   However, I am surprised that with 2.7.1 these do not work.   I
> > have found that on my Ubuntu system with Python 2.6.5 these Python 3
> > syntax items do seem to work properly.  I am assuming they were back
> > ported or something.  I would have expected the same for 2.7.1.
> >
> > --Bill
>
> I'm using Python 2.6.6 and I have a feeling you are not using python
> 2.6.5 with Python3 syntax working. I could be very wrong, but just a
> hunch ;)
>
> ~Corey
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-13 Thread Bill Allen
Vern,

Quite right!   I see what you mean.  I quite inadvertently stumbled into
examples that would work without realizing it.   I typically program in
Python 3, so not as familiar with the limitations on Python 2x.   I've had
quite a chuckle over this!

Thanks,
Bill


On Thu, Jan 13, 2011 at 10:31 PM, Vern Ceder  wrote:

> Bill,
>
> Try this:
>
> >>> print("hello", "Bill")
> ('Hello', 'Bill')
> >>> x = input("Your name?")
> Your name?Bill
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 1, in 
> NameError: name 'Bill' is not defined
>
> and see if those work (my results on 2.6 shown). In Python 3 the results
> are:
>
> >>> print ("Hello", "Bill")
> Hello Bill
> >>> x = input("Your name?")
> Your name?Bill
> >>>
>
> Cheers,
> Vern
> The two examples you show would work on any Python 2.x (or even 1.5)
> system. The  parens around the single string won't cause an error nor will
> using input to get an integer.
>
> Cheers,
> Vern
>
> On Thu, Jan 13, 2011 at 11:18 PM, Bill Allen  wrote:
>
>> I will agree that it seems odd, but here is a sample run from my system.
>> I promise I am not pulling anyone's leg!   :-))
>>
>> wallenpb@Ubuntu-D810:~$ python
>> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
>> [GCC 4.4.3] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> print("hello world")
>> hello world
>> >>> x = input("how many?")
>> how many?5
>> >>> x
>> 5
>>
>> On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson  wrote:
>>
>>> On 01/13/2011 10:29 PM, Bill Allen wrote:
>>> > That is correct about the difference between Python 2 and Python 3
>>> > syntax.   However, I am surprised that with 2.7.1 these do not work.
>>> I
>>> > have found that on my Ubuntu system with Python 2.6.5 these Python 3
>>> > syntax items do seem to work properly.  I am assuming they were back
>>> > ported or something.  I would have expected the same for 2.7.1.
>>> >
>>> > --Bill
>>>
>>> I'm using Python 2.6.6 and I have a feeling you are not using python
>>> 2.6.5 with Python3 syntax working. I could be very wrong, but just a
>>> hunch ;)
>>>
>>> ~Corey
>>>
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Vern Ceder
> vce...@gmail.com, vce...@dogsinmotion.com
> The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-13 Thread Bill Allen
I will agree that it seems odd, but here is a sample run from my system.  I
promise I am not pulling anyone's leg!   :-))

wallenpb@Ubuntu-D810:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello world")
hello world
>>> x = input("how many?")
how many?5
>>> x
5

On Thu, Jan 13, 2011 at 9:31 PM, Corey Richardson  wrote:

> On 01/13/2011 10:29 PM, Bill Allen wrote:
> > That is correct about the difference between Python 2 and Python 3
> > syntax.   However, I am surprised that with 2.7.1 these do not work.   I
> > have found that on my Ubuntu system with Python 2.6.5 these Python 3
> > syntax items do seem to work properly.  I am assuming they were back
> > ported or something.  I would have expected the same for 2.7.1.
> >
> > --Bill
>
> I'm using Python 2.6.6 and I have a feeling you are not using python
> 2.6.5 with Python3 syntax working. I could be very wrong, but just a
> hunch ;)
>
> ~Corey
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-13 Thread Bill Allen
That is correct about the difference between Python 2 and Python 3 syntax.
However, I am surprised that with 2.7.1 these do not work.   I have found
that on my Ubuntu system with Python 2.6.5 these Python 3 syntax items do
seem to work properly.  I am assuming they were back ported or something.  I
would have expected the same for 2.7.1.

--Bill

On Thu, Jan 13, 2011 at 7:55 PM, Corey Richardson  wrote:

> On 01/13/2011 08:50 PM, Elwin Estle wrote:
> > I am going through the book mentioned in the subject line, and I have
> found a couple of things that don't seem to work the way the author shows in
> the book.  So, either I am doing something wrong, or what he is saying isn't
> quite right.
> >
> > I am using Python 2.7.1 on Mac OS X Leopard.
> >
> > The first thing is what he has for getting keyboard input (this is
> non-GUI stuff).
> >
> > Several times he does something like this:
> >
> > x = input('type something: ")
> >
> > But when I do the above and type something in, I get an error message
> saying that whatever I have typed in response to the above input() command,
> is an undefined name, unless I put it in quotes when I type it.  I did a bit
> of poking around on the net and found out that input() actually appears to
> treat whatever is typed as an actual python command, i.e. as if it was being
> "eval"ed.   If this is the case...why does he describe the usage this way in
> his book?
> >
> > On the other hand, raw_input() works just as exected, is it a typo?
>  Seems like kind of a bad error to have in a Python book for beginners.
> >
> > And I just found another one that doesn't appear to work as he describes.
> >
> > print("some text here", end = ' ')
> >
> > He says this is supposed to control the end character on a print
> statement, allowing one to choose what the last character printed will be,
> other than a newline.  But when I try it, I get a syntax error on the "="
> after "end".
> >
> > So is this not a valid command format?  Or is he using perhaps an earlier
> version of python?  The copyright date on the book is 2010, and it is the
> 3rd Edition of the book.
> >
> >
> >
>
> He's not using an older version - you are! That book was written for
> Python 3.x, you are using Python 2.x. As you have found, replace input
> with raw_input, and for that print statement you can use:
>
> print "Some text",
>
> The comma suppresses the newline from being printed.
>
> HTH,
> ~Corey
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting a List

2011-01-12 Thread Bill Allen
Corey,

I have a bit of code that use in a CGI that sorts some picture files,
perhaps something like this will work for you.

The file sorting bit:
dir_list = os.listdir("/localhost/html/pics")
dir_list.sort()  #sorts the list of filenames in place

Just in case there is something else useful in the routine I am using, here
is the total code.   It not produces a sorted list of the file names, it
keeps the amount of files in the directory from growing out of control in my
particular Python CGI app.   In this case, I keep only the 5 most recent
files.  The code does not have to look at the file timestamps to do this
because I am using the epoch time at time of the file's creation as the
file's name i.e.  from time import time; new_filename = str(int(time()))
.

file_list = ""
count = 0
dir_list = os.listdir("/localhost/html/pics")
dir_list.sort()
for file in dir_list:
count = count + 1
if count < 5:
pass
else:
basename = os.path.basename(file)
if basename.endswith('.png'):
file_list = file_list + basename+'\n'
        os.remove("/localhost/html/pics/"+dir_list[0])

--Bill Allen



On Wed, Jan 12, 2011 at 6:56 PM, Corey Richardson  wrote:

> Hello Tutors,
>
> I am generating XML definitions for animations to be used in a
> FIFE-based game. I need to sort the frames of the animations, and I am
> currently using:
> sorted([image for image in os.listdir(path) if image.endswith('.png')])
>
> The final output in the XML is:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Having frame 10 and 11 between frame 1 and 2 is not desired behavior;
> how can I sort all of these with walk_10.png and company (this isn't the
> only animation like this) being after walk_9.png? A google search
> doesn't return anything I could use. I tried just using
> [image for image in os.listdir(path) if image.endswith('.png')],
> but that doesn't appear to have any order.
>
> Thanks,
> Corey Richardson
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-14 Thread Bill Allen
Still looking on this one, but I will be sure to post back to the list if I
find anything.

Thanks,
Bill Allen


On Tue, Dec 14, 2010 at 5:23 AM, Steven D'Aprano wrote:

> Bill Allen wrote:
>
>> Anyone know how to get WConio.putch() to properly put out a box drawing
>> character to the screen in the while at a cmd prompt?   The code page is
>> 437, but it when I tell it to put out 188, for example, it get a 1/4
>> character instead of the box drawing character.
>>
>
> My guess is that there is a mis-match between the code page you think you
> have, the code page you actually have, and the encoding that your terminal
> is set to.
>
> I suspect though that you might need to take this to a specialist WConio
> mailing list, if there is one, or at least the main Python list:
> pyt...@python.org or comp.lang.python.
>
>
> Good luck, and if you do find the solution, don't forget to post it here
> for future reference.
>
>
> --
> Steven
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread Bill Allen
Anyone know how to get WConio.putch() to properly put out a box drawing
character to the screen in the while at a cmd prompt?   The code page is
437, but it when I tell it to put out 188, for example, it get a 1/4
character instead of the box drawing character.

I am using WConio.putch(188)

I have it WConio through the whole 0 thru 256 range
import WConio
for i in range(0,257):
 WConio.putch(i)

and get:

♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼
!"#$%&'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂??
?? 
¡¢£☼¥▌§"cª«¬-r_°±²3'µ¶·,1º»¼½_¿ÄÅÆÇEÉEEDÑÖxOUUUÜY_ßàáâaäåæçèéêëìíîïdñòóôoö÷oùúûüy_ÿA

However if at the cmd prompt, out side of Python, I give it an Alt-188 I get
the correct  ╝

Where am I going wrong?

Thanks,
Bill Allen




On Mon, Dec 13, 2010 at 12:53 PM, Bill Allen  wrote:

> Alan,
>
> Oh wow!   I was not aware of the WConio module.   That is exactly what I
> have been needing!
>
>
>
> Thanks,
> Bill Allen
>
>
>
>
> On Sun, Dec 12, 2010 at 6:49 PM, Alan Gauld wrote:
>
>>
>> "Modulok"  wrote
>>
>>  For more complex stuff, (think blue screens with little white boxes
>>> you press spacebar to activate. Kind of like an OS installer) I would
>>> look into the `curses` module in the standard library?
>>>
>>
>> curses on Unix but its not in the std library for windows.
>>
>> I think there is a version you can download, and there are also
>> libraries specifically for the PC terminal, one that I've used
>> successfully being Wconio, based on the Borland Turbo-C
>> console I/O package conio.h.
>>
>> Conio is on Sourceforge.
>>
>> HTH,
>>
>>
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread Bill Allen
Alan,

Oh wow!   I was not aware of the WConio module.   That is exactly what I
have been needing!



Thanks,
Bill Allen



On Sun, Dec 12, 2010 at 6:49 PM, Alan Gauld wrote:

>
> "Modulok"  wrote
>
>  For more complex stuff, (think blue screens with little white boxes
>> you press spacebar to activate. Kind of like an OS installer) I would
>> look into the `curses` module in the standard library?
>>
>
> curses on Unix but its not in the std library for windows.
>
> I think there is a version you can download, and there are also
> libraries specifically for the PC terminal, one that I've used
> successfully being Wconio, based on the Borland Turbo-C
> console I/O package conio.h.
>
> Conio is on Sourceforge.
>
> HTH,
>
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using a networked data file

2010-12-12 Thread Bill Allen
Wayne,

Yes, you have characterized it pretty well.  Additionally, it will be
accessed typically by maybe a dozen individuals, typically only reading
information from the database and infrequently writing to it.

--Bill

On Sun, Dec 12, 2010 at 7:36 AM, Wayne Werner wrote:

>
>
>  I think the larger concern is how the users are accessing the DB. Multiple
> clients on multiple computers accessing the same db file on an accessible
> network location? Or something else?
>
> There are plenty of pitfalls to be aware of depending on your use.
>
> -Wayne
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using a networked data file

2010-12-11 Thread Bill Allen
David,

Thanks for the feedback.   I should have been more specific on the usage of
the data.   The data will be some email addresses, names, department, and an
indicator if the email address is internal to the business or an external
contact.   So, one table with these being the fields in each record should
suffice.   The users will be presented an interface that allows them to
select one or more recipients to which a standardized email with a PDF
attachment will be sent.   All of this is no problem.   I was concerned that
with more than one user at a time potentially accessing the SQLite db at a
time would be a problem, but I see from the SQLite site and from some
discussions here on Tutor that this is perfectly fine.   The users may add
information to the db also, but since such writes will be infrequent this
too should be OK.   At least, that is the impression that I have gotten from
what I have read here and other places.   Just wanting to confirm that I
have understood this correctly.  Also, any other suggestions are welcome.

Thanks,
Bill Allen


On Sat, Dec 11, 2010 at 6:32 AM, David Hutto  wrote:

> On Fri, Dec 10, 2010 at 10:23 PM, Bill Allen  wrote:
> > This is somewhat non-Python specific   I have an idea for a Python
> > application that I want to write at work.  The application needs to have
> a
> > data file be available to multiple users for access, read and write.   I
> > know that a typical database, such as mysql, would work ok.   However, I
> am
> > trying to keep managed infrastructure down to a minimum so I am
> considering
> > using sqlite instead.   Since there is not a database service running to
> > handle requests to the sqlite database, how can I allow for multiple
> people
> > trying to use this database at the same time?  Is this practical?
>
> No expert, but is it a single db file per user on a server, or a
> single db file that adds a table for every user?
>
>
> >
> > Thanks,
> > Bill Allen
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using a networked data file

2010-12-10 Thread Bill Allen
This is somewhat non-Python specific   I have an idea for a Python
application that I want to write at work.  The application needs to have a
data file be available to multiple users for access, read and write.   I
know that a typical database, such as mysql, would work ok.   However, I am
trying to keep managed infrastructure down to a minimum so I am considering
using sqlite instead.   Since there is not a database service running to
handle requests to the sqlite database, how can I allow for multiple people
trying to use this database at the same time?  Is this practical?

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


Re: [Tutor] Ide To use? Other extras to install?

2010-10-13 Thread Bill Allen
On Mon, Oct 11, 2010 at 8:53 AM, Jed Smith  wrote:

> On Sun, Oct 10, 2010 at 9:31 PM, Jorge Biquez  wrote:
>
> > What would be the IDE you recommend me to install that would be almost
> > transparent to be using in both platforms?
>
>
> I personally best like the one that is most closely associated with Python,
that is IDLE.   It looks and works the same whether I am in Windows or
Linux.   It is not real fancy, but it does has a good text editor with
reasonable features and the interactive window for testing and program run.
It also supports enough debugging functions to be helpful.  It is very
simple and often comes with the Python distribution. (comes with the Windows
distribution, separate install on Linux)

Just my 2 cents worth.   A buddy of mine prefers to program using the Kate
editor on Linux.   I sometimes use gedit on Linux and Notepad++ on Windows.
  In the end, the best IDE/editor is the one you know and feel comfortable
with.  I suggest you start with IDLE and see if you find some reason not to
like it.

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


Re: [Tutor] EXECUTING PYTHON AND SQL STAMENTS

2010-10-04 Thread Bill Allen
On Mon, Oct 4, 2010 at 9:04 AM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> I'm developing a module to execute an external command. The module executes
> the command, but in order to make my code useful I have to enter some sql
> staments. This is my code:
>

Question, what database system are you trying to access?   Python, via its
standard library, and also by easily available 3rd party libraries. has
ample facilities to allow for database access without having to do external
OS calls.   You may have a perfectly valid reason for designing your code
the way you have, but I thought this was worth asking.

--Bill

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


[Tutor] list comprehension, efficiency?

2010-09-27 Thread Bill Allen
I have seen list comprehensions used, but have not quite got the hang of it
yet.
So, I was writing a bit of code to do some work with file directories and
decided
to give it a try as follows:

list_c = os.listdir("c:")

#first code written in the way I usually would.
dirs = []
for x in list_c:
if os.path.isdir(x):
dirs.append(x)

#replaced the above code with the following list comprehension, it worked as
expected:
dirs = [x for x in list_c if os.path.isdir(x)]

I can now see that quite a bit of the code I write dealing with lists can be
done with list
comprehensions.   My question is this, is the list comprehension styled code
generally
more efficient at runtime?  If so, why?

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


Re: [Tutor] a logic problem in an if statement

2010-09-26 Thread Bill Allen
On Sun, Sep 26, 2010 at 5:12 PM, Steven D'Aprano wrote:

> On Mon, 27 Sep 2010 06:01:35 am Bill Allen wrote:
>
> Now your decision logic becomes simple, and obvious. It documents
> itself:
>
> if click_in_bottom_half1 and click_in_bottom_half2:
>print "Both clicks in bottom half of screen"
> elif click_in_bottom_half1:
>print "The first click was in the bottom half."
>print "The second click was in the top half."
> elif click_in_bottom_half2:
>print "The first click was in the top half."
>print "The second click was in the bottom half."
> else:
>print "Both clicks in top half of screen"
>
>
>
> --
> Steven D'Aprano
>

Steven,

Those are great suggestions and certainly do simplify matters quite a bit.
I had not realized the I was including such redundancies into my code.  I
have some other code I need to now go back through and see what
simplifications I can there also make.

Thanks!

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


Re: [Tutor] generating formatted output

2010-09-26 Thread Bill Allen
On Sun, Sep 26, 2010 at 4:21 PM, Hugo Arts  wrote:

> On Sun, Sep 26, 2010 at 10:16 PM, Rance Hall  wrote:
> > My app will be printing a series of documents that are the same each
> > time the doc is printed with the exception of the variables.  Sort of
> > a MailMerge if you will.
> >
> >
>
> I would suggest you take a look at string.Template or the str.format
> method. It may be somewhat simpler than doing a whole lot of replaces,
> perhaps faster as well.
>
> http://docs.python.org/library/string.html#template-strings
> http://docs.python.org/library/stdtypes.html#str.format
>
> Hugo
>
> I agree.   I had a great deal of success with using docstrings along with
str.format in a program I wrote at work.

Example, two ways:

"""
Dear Mr. {0},

Thanks for your recent inquiry.

Your current invoice #{1} is overdue by {2} days.

Please make remittance by {3} in order to avoid
overdue fees.

Sincerely,
{4}
Billing Dept.
""".format(client_name, inv_num, num_days, due_date, sender)

or

over_due_notice = """

Dear Mr. {0},

Thanks for your recent inquiry.

Your current invoice #{1} is overdue by {2} days.

Please make remittance by {3} in order to avoid
overdue fees.

Sincerely,
{4}
Billing Dept.
"""

over_due_notice.format(client_name, inv_num, num_days, due_date, sender)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python And reading the Web - Javascript

2010-09-26 Thread Bill Allen
On Sat, Sep 25, 2010 at 4:29 AM, Sayth Renshaw wrote:

> I want to read some data from the web it will be text and numeric i
> was planning to export it to a database. I was thinking while I am
> learning maybe something simple like Sqlite or MySQL.
>
> I then want to read back data to perform sorting and some calculations on.
>
> This might be a good starting place for you.

http://diveintopython.org/html_processing/extracting_data.html

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


Re: [Tutor] a logic problem in an if statement

2010-09-26 Thread Bill Allen
On Sun, Sep 26, 2010 at 3:12 PM, Marc Tompkins wrote:

> On Sun, Sep 26, 2010 at 1:01 PM, Bill Allen  wrote:
>
>>
>> Any thoughts how I am going wrong here?
>>
>> Looks like you've got two different names for the first mouse click...
>
> mouse_pos1 = mouse_pos
>>
>
> but
>
> if mouse_pos[1] < height/2 and mouse_pos2[1] > height/2:
>>
>
>
> Bingo!  Yes, that's the problem.  Should have  been if mouse_pos1[1] <
height/2 and mouse_pos2[1] > height/2:  rather than if mouse_pos[1] <
height/2 and mouse_pos2[1] > height/2:

That was basically a typo to which I had become completely blind.  I did it
in the second case as well, but it did not affect the result in that case,
making it even harder for me to spot.

I hate it when I do something like that!A combination of poor choice of
names for the variables and programming tunnel vision

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


[Tutor] a logic problem in an if statement

2010-09-26 Thread Bill Allen
Ok, I am have a problem with some logic in a piece of code I am working
on.   I have tinkered with it for hours and am stumped.  Pretty sure I have
lost sight of the forest for the trees...

The purpose of this code is to take the coordinates on screen of the mouse
at the time of two mouse clicks, store that information and then make some
decisions based on that.  No matter what I do, I am finding that the second
if statement block falls through to the last option.   In the if I am try to
say "if the mouse click cursor position with the first click was in the
upper half of the screen (i.e. < height/2) and the second mouse click was in
the lower half of the screen (i.e. > height/2)".  elif "both clicks happened
in the upper half of the screen"   else "assume the clicks occurred in the
lower half of the screen".  The second case and last case always seem to
work out ok.  The first case falls through to the final case even though the
coordinates were appropriate for the first case logic.

Any thoughts how I am going wrong here?

--Bill

#This captures the coordinates the two mouse clicks, successfully.
mouse_pos is in the form (x,y), such as (204,102).
if mouse_pressed == (1,0,0) and first_click == False:
first_click = True
mouse_pos1 = mouse_pos
elif mouse_pressed == (1,0,0) and first_click == True:
mouse_pos2 = mouse_pos

#This is the decisional logic based on the mouse click coordinates,
previously captured.
#This first case fails although the print statement give me feedback on the
coordinates,
#that suggest it should have worked.  It always falls through to the final
else.
if mouse_pos[1] < height/2 and mouse_pos2[1] > height/2:
print("use 0 for new yadjust")
print(height/2,"did first one", mouse_pos1[1], mouse_pos2[1])

#This case always works.
elif mouse_pos[1] < height/2 and mouse_pos2[1] < height/2:
print("use {0} for new
yadjust".format(1.05+(1-((height/2)-mouse_pos1[1])/(height/2
print(height/2,"did 2nd one", mouse_pos1[1], mouse_pos2[1])

#this case always works.
else:
print("use {0} for new
yadjust".format(-1.07+(1+((height/2)-mouse_pos2[1])/(height/2
print(height/2,"did last one", mouse_pos1[1], mouse_pos2[1])
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-19 Thread Bill Allen
On Sun, Sep 19, 2010 at 2:40 AM, Lie Ryan  wrote:

>
> More slowly and takes huge amount of memory. A single Tk canvas object
> takes at least 14 words (= 114 bytes in 64-bit OS = 56 bytes in 32-bit
> OS) + the amount of data is needed to store the `kind of object`. That's
> much larger than the ideal 3 bytes per pixel (or 4 bytes with alpha).
>
> Tkinter's Canvas intentionally doesn't provide create_pixel() because
> unlike most other Canvas implementations, Tkinter's Canvas holds a
> stateful canvas objects instead of a simple drawing surface. Providing a
> create_pixel() will be too tempting for abuse, which would make the
> canvas unbearably slow and memory consuming. In short, Canvas is not
> designed for pixel drawing.
>
> > Digging a little deeper it seems the idiomatic way to do this in Python
> > is to use PIL the Python Imaging Library to create a GIF or bitmap
> > image and then insert that into Tkinters cancvas as an image object.
> >
> > The Pil ImageDraw class has a point() ethod
>
> If you need to plot pixels, do use pygame, PIL, or at least the
> PhotoImage trick.
>
> Thanks for the feedback!   That does make a lot a sense as to why a
pixel_plot() type function would not be directly implemented in Canvas.  As
this is still largely a learning exercise for me, I may try more than one
approach.  I think first I will try the PhotoImage approach, which might be
the most efficient method.  However, I will definitely give Pygame a try.  I
have seen several programs that were written in Pygame and I am really
impressed!  It is obviously designed to task.

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


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 9:26 PM, Bill Allen  wrote:

>
>
>> Digging a little deeper it seems the idiomatic way to do this in Python
>> is to use PIL the Python Imaging Library to create a GIF or bitmap
>> image and then insert that into Tkinters cancvas as an image object.
>>
>> The Pil ImageDraw class has a point() ethod
>>
>> I've never tried this but it is described in Grayson's (now out of print?)
>>
>> book on Tkinter where he uses it to draw a Mandelbrot
>> The book may be available online these days...
>>
>> Nowdownloadall.com seems to have it although I've no idea
>> of the legality of it!
>>
>> HTH,
>>
>> Alan G.
>>
> Yes, to create a gif or a bmp from the iteration results and then to
> display that at the end of the run is by far the most efficient way of
> producing Mandelbrot and related sets.  I have actually done it that way
> before.   I just have always had a strange preference to see the set as it
> is being produced, which is far from efficient.  Kind of a very elaborate
> progress bar!  Anyway, I have no real complaints about the Tk canvas
> methods.  It has always just been a pet peeve of mine when something as
> basic and simple as plotting a pixel is missing.  My complaint on this goes
> way back to the ancient days when I had to figure out how to write a
> plot_pixel primitive in x86 assembler and then build a graphics library of
> my own so I could have pixel based graphics on my old monochrome IBM XT
> clone that had a Hercules graphics card in it.  Those were the days!
> Mandelbrot sets in 4 shades of amber-monochrome!;-)   I will check out
> that book you referenced.   I appreciate everybody's feedback on this.
>
> -Bill
>
>
> I found this code on the web.  It creates a 100x100 tk.photoimage  and
fills it with a radom colored pixels then displays it.  It seems to me that
I should be able to adapt this to what I am trying to acomplish.  The only
difference in the way I am filling the tk.photoimage object.  I ran this
under Python 3.1.2 with success.  I believe the '#%02x%02x%02x' is the
format for an image.   It is a color photoimage, but I am presuming that if
written directly out to a file this would not actually produce a valid, bmp,
gif, pgn, etc.  Correct?   This does seem to be a reasonable solution that
is a pure Tk solution.  Also it works in Python 3x, whereas the PIL library
has not yet been released for 3x.   I have not mentioned it before, but
using Python 3x only is also one of my requirement, though self-imposed.
Can anyone help me better understand this part of the code below?
self.i.put('#%02x%02x%02x' % tuple(color),(row,col))

import tkinter, random
class App:
def __init__(self, t):
self.i = tkinter.PhotoImage(width=100,height=100)
colors = [[random.randint(0,255) for i in range(0,3)] for j in
range(0,1)]
row = 0; col = 0
for color in colors:
self.i.put('#%02x%02x%02x' % tuple(color),(row,col))
col += 1
if col == 100:
row +=1; col = 0
c = tkinter.Canvas(t, width=100, height=100); c.pack()
c.create_image(0, 0, image = self.i, anchor=tkinter.NW)

t = tkinter.Tk()
a = App(t)
t.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
>
> Digging a little deeper it seems the idiomatic way to do this in Python
> is to use PIL the Python Imaging Library to create a GIF or bitmap
> image and then insert that into Tkinters cancvas as an image object.
>
> The Pil ImageDraw class has a point() ethod
>
> I've never tried this but it is described in Grayson's (now out of print?)
> book on Tkinter where he uses it to draw a Mandelbrot
> The book may be available online these days...
>
> Nowdownloadall.com seems to have it although I've no idea
> of the legality of it!
>
> HTH,
>
> Alan G.
>
Yes, to create a gif or a bmp from the iteration results and then to display
that at the end of the run is by far the most efficient way of producing
Mandelbrot and related sets.  I have actually done it that way before.   I
just have always had a strange preference to see the set as it is being
produced, which is far from efficient.  Kind of a very elaborate progress
bar!  Anyway, I have no real complaints about the Tk canvas methods.  It has
always just been a pet peeve of mine when something as basic and simple as
plotting a pixel is missing.  My complaint on this goes way back to the
ancient days when I had to figure out how to write a plot_pixel primitive in
x86 assembler and then build a graphics library of my own so I could have
pixel based graphics on my old monochrome IBM XT clone that had a Hercules
graphics card in it.  Those were the days!  Mandelbrot sets in 4 shades of
amber-monochrome!;-)   I will check out that book you referenced.   I
appreciate everybody's feedback on this.

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


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 1:18 PM, Ken Oliver wrote:

>
>
>> On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld wrote:
>>
>>>
>>> For plotting pixels I would not use turtle graphics.
>>> That would be a fairly complicated option I'd have thought.
>>> A simple canvas would be easier.
>>>
>>> Alan G.
>>>
>>>
>> Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.
>> I will have to play with that and see if I can get everything done in the
>> code I am working with.  What I am doing is just trying to do a simple
>> Mandelbrot set plot.  It is another bit of coding that I do when learning a
>> new language to get a handle on some of the graphics capabilities, and I am
>> to that point.
>>
>> -Bill
>>
>  It appears that the Tk canvas widget does not support simply plotting a
> pixel.  However, I can plot a line only one pixel long.   I wonder why they
> do not simply provide the pixel plot primitive?  I have seen very many
> graphics packages that do this and I have always wondered why.  The
> primitive obviously exists in the underlying code, because that is what
> everything else is built upon.  Does Tk actually have a something like a
> create_pixel method in the canvas widget that I have missed?
>
> -Bill
>
> Is it naive of me to ask, "Couldn't one write his own plotpixel( ) function
> using the line() function?"
>
>  .
>
> No, not naive at all.  Indeed I could, but that is not the issue in my
mind.  My point is that it seems strange to me that any graphics package
would not make the most basic of the routines, ploting a single pixel,
available.   I think I actually see a way of doing it with the bitmap class,
but that is not the point.  While I could do exactly as you have said, I
would rather either write my own low-level code to accomplish that or use a
package that does provide it than to wrap up a higher end function, such as
drawing a line or rectangle, into even more code in order to do less.   For
the particular use that I am going to put this to, a package such as pygame
which does provide the ability to plot pixels directly will be more
suitable.

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


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 10:44 AM, Bill Allen  wrote:

>
>
> On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld wrote:
>
>>
>> For plotting pixels I would not use turtle graphics.
>> That would be a fairly complicated option I'd have thought.
>> A simple canvas would be easier.
>>
>> Alan G.
>>
>>
> Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.
> I will have to play with that and see if I can get everything done in the
> code I am working with.  What I am doing is just trying to do a simple
> Mandelbrot set plot.  It is another bit of coding that I do when learning a
> new language to get a handle on some of the graphics capabilities, and I am
> to that point.
>
> -Bill
>
 It appears that the Tk canvas widget does not support simply plotting a
pixel.  However, I can plot a line only one pixel long.   I wonder why they
do not simply provide the pixel plot primitive?  I have seen very many
graphics packages that do this and I have always wondered why.  The
primitive obviously exists in the underlying code, because that is what
everything else is built upon.  Does Tk actually have a something like a
create_pixel method in the canvas widget that I have missed?

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


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld wrote:

>
> For plotting pixels I would not use turtle graphics.
> That would be a fairly complicated option I'd have thought.
> A simple canvas would be easier.
>
> Alan G.
>
>
Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.  I
will have to play with that and see if I can get everything done in the code
I am working with.  What I am doing is just trying to do a simple Mandelbrot
set plot.  It is another bit of coding that I do when learning a new
language to get a handle on some of the graphics capabilities, and I am to
that point.

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


Re: [Tutor] plotting pixels

2010-09-16 Thread Bill Allen
On Thu, Sep 16, 2010 at 9:21 PM, James Mills
wrote:

> On Fri, Sep 17, 2010 at 12:13 PM, Bill Allen  wrote:
> > Is there a simple way to plot pixels in Python, without resorting to
> turtle
> > graphics?
>
> Give matplotlib a go.
>
> Alternatively you may want to try pygame or pyglet.
>
> cheers
> James
>
> --
> -- James Mills
> --
>
Thanks!  I'll give those a try.

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


[Tutor] plotting pixels

2010-09-16 Thread Bill Allen
Is there a simple way to plot pixels in Python, without resorting to turtle
graphics?


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


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread Bill Allen
On Wed, Sep 15, 2010 at 10:35 PM, David Hutto  wrote:

> print("a is", a)
> or
> from future import *
> ___
>

Other than the Python 3 style print function, what else is contained in the
future module?

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


Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Bill Allen
>
>> Second question is more of a performance question:
>>
>> I don't suspect a "large" # of items in the to_do list, so I *think*
>> that it would be better to just have one SQL statement and then loop
>> through the results 10 times to get the first few records rather than
>> having a seperate sql statement as I have shown here.  I'm too new at
>> python to have a feel for the *right* way to go about this part
>>
>> Could someone point me in the right direction please?
>>
>
As to your second question, I had the same question a few days ago that the
folks here helped me out with.  if you have a list of items you can limit
the loop to get just the first ten items like this:

for x in list_of_results[:10]
 do something with x...

If your object does not easily lend itself to applying a slice, then look
into the itertools module and the islice() method which can help you get and
iterable list from a normaly non-iterable source, like this:

import itertools
for x in itertools.islice(results, 0, 10)
do something with x...


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


Re: [Tutor] py-postgressql v1.0.1 question

2010-09-12 Thread Bill Allen
Rance,

I was doing something similar, except I was querying an Oracle database,
using the cx_Oracle module.  I wanted the non-duplicated count of parts in
my database that met certain criteria.  All the output that met the criteria
of the select statements is loaded into the cursor object.  I then loop
through the cursor object appending the contents into a list.   Then I
converted the list to a set to blow out the duplicates and then back to a
list and took the len of the list for my final count.

#Fetch the list of parts
cursor.execute("select pobj_name from pfmc_part where pmodel = :arg_1 and
pstatus = :arg_2", arg_1 = "PN-DWG", arg_2 = "RELEASED")
for pobj_name in cursor:
Parts_List.append(pobj_name)

print("size of Parts_List before set operation =", len(Parts_List))
Parts_List = list(set(Parts_List))
print("size of Parts_List after set operation  =", len(Parts_List))

Perhaps you could loop though your get_todo object and load into a list and
do similar or just take a len of it directly if it is already a list.

-Bill

On Sun, Sep 12, 2010 at 10:55 AM, Rance Hall  wrote:

> I'm not sure if this is the right forum for this or not, if there is a
> better place to ask this question please let me know and I'll re-post
> elsewhere.
>
> I'm using python v3.1 and the py-postgresql v1.0.1 module located at
> http://python.projects.postgresql.org/docs/1.0/
>
> I'm using prepared sql statements like:
>
> insertnote = db.prepare("INSERT INTO business.to_do_list (note) VALUES
> ($1)")
> delete_note = db.prepare("DELETE FROM business.to_do_list WHERE item = $1")
>
> so far so good, everything is working well and I understand whats going on.
>
> But I have a situation where I want to count the number of notes in
> the database, and if 0 do something, and if 1 do something else.
> I have another occasion where I only want the first few records to be
> returned.
>
> So for testing the idea I did this:
>
> get_todo = db.prepare("SELECT note FROM business.to_do_list ORDER BY item")
> get_todo_limit = db.prepare("SELECT note FROM business.to_do_list
> ORDER BY item LIMIT 10")
> get_todo_count = db.prepare("SELECT COUNT(note) AS notecount FROM
> business.to_do_list")
>
> I *think* there is a better way to do this, but I'm not seeing it in
> the documentation, or its there and I'm not understanding it
> correctly.
>
> I suspect that the get_todo_count statement is not required at all.  I
> have a hunch, although I can't prove yet that the result set returned
> by the SQL SELECT statement will have some way to access the record
> count directly
>
> Something like this:
>
> m = get_todo_limit()
>
> if m.count == 0:
>do stuff
> else:
>do other stuff
>
> I can't quite narrow this down.  I'm sure its possible, It likely
> depends on what python variable type is used by the py-postgresql
> module, but I'm not seeing this in the docs.
>
> Second question is more of a performance question:
>
> I don't suspect a "large" # of items in the to_do list, so I *think*
> that it would be better to just have one SQL statement and then loop
> through the results 10 times to get the first few records rather than
> having a seperate sql statement as I have shown here.  I'm too new at
> python to have a feel for the *right* way to go about this part
>
> Could someone point me in the right direction please?
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SOLVED: Re: Trapping HTTP Authentication Failure

2010-09-12 Thread Bill Allen
Just in case it is not a known issue or well documented, do take the time if
you can to report it.  Especially since you have got the symptom isolated
and demonstrated that it is limited to a particular OS build.

http://docs.python.org/bugs.html


-Bill


On Sat, Sep 11, 2010 at 1:44 PM, Michael Powe  wrote:

> Hello,
>
> It is bloody Winblows.  The script works as designed and traps the 401
> exception on my slackware box ... something in the implementation of
> urllib2 on Windoze is broken.  This has to be a known issue.  Just did
> not see it known anywhere.
>
> Thanks.
>
> mp
>
> On Sat, Sep 11, 2010 at 02:16:07PM -0400, Michael Powe wrote:
> > On Sat, Sep 11, 2010 at 10:48:13AM -0400, Michael Powe wrote:
> > > On Sat, Sep 11, 2010 at 02:25:24PM +0200, Evert Rol wrote:
> > > > 
> > >
> > > > >> I'm not sure what you're exactly doing here, or what you're
> getting,
> > > > >> but I did get curious and dug around urllib2.py. Apparently, there
> is
> > > > >> a hardcoded 5 retries before the authentication really fails. So
> any
> > > > >> stack trace would be the normal stack trace times 5. Not the 30
> you
> > > > >> mentioned, but annoying enough anyway (I don't see how it would
> fail
> > > > >> for every element in the loop though. Once it raises an exception,
> > > > >> the program basically ends).
> >
> > > > > It never throws an exception.  Or, if it does, something about the
> way
> > > > > I'm calling suppresses it.  IOW, I can put in a bogus credential
> and
> > > > > start the script and sit here for 5 minutes and see nothing.  Then
> ^C
> > > > > and I get a huge stacktrace that shows the repeated calls.  After
> the
> > > > > timeout on one element in the list, it goes to the next element,
> times
> > > > > out, goes to the next.
> >
> > Hello,
> >
> > More experimentation revealed that one problem was testing the script
> > in Idle.  Idle does something to suppress the script failure for that
> > particular case (IOW, it correctly returns HTTPError for things like
> > '404' and URLError for things like a bad domain name).
> >
> > When I run the script from the command line (cmd), it actually ignores
> > the '5' retry limit, seemingly.  I added another catch block:
> >
> > except Exception as e:
> >  print "exception: ",e
> >
> > That prints out "exception: maximum recursion depth exceeded."
> >
> > I wonder if there is something hinky in Windows that is causing this
> > to happen.
> >
> > Thanks.
> >
> > mp
> >
> > > > Ok, now I had to try and recreate something myself. So my processData
> is:
> > >
> > > > def processData(f):
> > > >global overview_url
> > > >overview_url = baseurl + f
> > > >getData(authHeaders)
> > > >
> > > > (f being a filename, out of a list of many). Other code same as
> yours.
> > >
> > > > It definitely throws a 401 exception after 5 retries. No time-outs,
> > > > no long waits. In fact, a time-out would to me indicate another
> > > > problem (it still should throw an exception, though). So, unless
> > > > you're catching the exception in processData somehow, I don't see
> > > > where things could go wrong.
> > >
> > > > I assume you have no problem with correct credentials or simply
> > > > using a webbrowser?
> > >
> > > Hello,
> > >
> > > Yes, I can retrieve data without any problem.  I can break the URL and
> > > generate a 404 exception that is trapped and I can break it in other
> > > ways that generate other types of exceptions.  And trap them.
> > >
> > > I went back and looked at the code in urllib2.py and I see the
> > > timeout counter and that it raises an HTTPError after 5 tries.  But I
> > > don't get anything back.  If I just let the code run to completion, I
> > > get sent back to the prompt.  I put a try/catch in the method and I
> > > already have one on the call in main.
> > >
> > >
> > >
> > > > >> I don't know why it's hard-coded that way, and not just an option
> > > > >> with a default of 5, but that's currently how it is (maybe someone
> > > > >> else on this list knows?).
> > > > >
> > > > > I don't know, but even if I could set it to 1, I'm not helped
> unless
> > > > > there's a way for me to make it throw an exception and exit the
> loop.
> > >
> > > Actually, there's a comment in the code about why it is set to 5 --
> > > it's arbitrary, and allows for the Password Manager to prompt for
> > > credentials while not letting the request be reissued until 'recursion
> > > depth is exceeded.'
> > >
> > > I guess I'll have to go back to ground zero and write a stub to
> > > generate the error and then build back up to where it disappears.
> > >
> > > Thanks.
> > >
> > > mp
> > >
> > > --
> > > Michael Powemich...@trollope.orgNaugatuck
> CT USA
> > > It turns out that it will be easier to simply block the top offenders
> > > manually; the rules for pattern matching are too arcane, obscure, and
> > > difficult to program. -- t. pascal, comp.mail.misc, "procmail to
> > > filter spam"
> >
> >
> >
>

Re: [Tutor] Simple Python Problem

2010-09-06 Thread Bill Allen
>Other than changing the input() to raw_input() for Python 2 compatibility,
>
>
> And of course you can do that using
>
> input = raw_input
>
>
> > the following statement could be added to the beginning of the program
> > to allow your Python 2 program to use the Python 3 style print function.
>
> from __future__ import print_function
>
> That would help.
> I wonder if we could create a module that would make v2.7 simulate v3 to
> a close degree? hmm... And is it sensible to try, should we not perhaps
> just accept the difference?
>
> Alan G.
>
>  Ah!  I did not know that input = raw_input would work, thanks!

I am sure someone could create such.  However, to me, it would be more
sensible to just program in v3.  I have decided to code in only v3 since I
do not have any previous code base to maintain and am still very much in
learning mode.   It seems that some of the more popular external modules
such as NumPy and PyGame are also now v3 compatible.

By the way, even though I am far from proficient with Python, it has already
become a useful tool for me at work!

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


Re: [Tutor] Simple Python Problem

2010-09-06 Thread Bill Allen
>
>
>  Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)]
>> on win32 Type
>> "copyright", "credits" or "license()" for more information.
>>
>>>  RESTART 
>
 What is your name? Keith
>>
>
> I think there is a trick in V2.7 to make it act more like v3 but someone
> else will need to tell you what it is... :-)
>
>
Other than changing the input() to raw_input() for Python 2 compatibility,
the following statement could be added to the beginning of the program to
allow your Python 2 program to use the Python 3 style print function.

from __future__ import print_function


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


Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Bill Allen
Thanks to everyone who replied.   Some of the methods presented where some I
had thought of, others were new to me.   Particularly, I did not realize I
could apply a slice to a list.   The for x in some_stuff[:value] form worked
very well for my purposes.  I can also see I need to look into the itertools
module and see what goodies are to be found there.

-Bill



On Sat, Sep 4, 2010 at 2:07 PM, Dave Angel  wrote:

>
>
> Bill Allen wrote:
>
>> Say I have and iterable called some_stuff which is thousands of items in
>> length and I am looping thru it as such:
>>
>> for x in some_stuff
>> etc...
>>
>> However, what if I want only to iterate through only the first ten items
>> of
>> some_stuff, for testing purposes.  Is there a concise way of specifying
>> that
>> in the for statement line?
>>
>>
>> -Bill
>>
>>
>>
> You could use islice()
>
> import itertools
> for x in itertools.islice(some_stuff, 0, 10)
>   print x
>
> DaveA
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] iterating over less than a full list

2010-09-04 Thread Bill Allen
Say I have and iterable called some_stuff which is thousands of items in
length and I am looping thru it as such:

for x in some_stuff
 etc...

However, what if I want only to iterate through only the first ten items of
some_stuff, for testing purposes.  Is there a concise way of specifying that
in the for statement line?


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


Re: [Tutor] question about import statement

2010-08-26 Thread Bill Allen
>
> On Thu, Aug 26, 2010 at 7:44 PM, Corey Richardson  wrote:
>
>> Why don't you try it out without the "from tkinter import ttk" statement,
>> and see if it works?
>>
>> Bill Allen wrote:
>>
>>> I was experimenting with Tk today, just trying it out.   I found this
>>> example of a very simple "hello world" button click program.  This is it.
>>>
>>> from tkinter import *
>>> from tkinter import ttk
>>>
>>> root = Tk()
>>> button = ttk.Button(root, text="Hello World").grid()
>>> root.mainloop()
>>> What I don't understand is why it is necessary to run that import
>>> statement twice.  Shouldn't import * bring everything in from tkinter?
>>>
>>>
Oops, sorry about the previous empty post.

I did try that and of course it gave an error because it was necessary.  I
just did not know why.   However, I later found an explanation on the web.
Here it is:

*from tkinter import *
from tkinter import ttk

These two lines tell Python that our program needs two modules. The first,
"tkinter", is the standard binding to Tk, which when loaded also causes the
existing Tk library on your system to be loaded. The second, "ttk", is
Python's binding to the newer "themed widgets" that were added to Tk in 8.5.
*


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


Re: [Tutor] question about import statement

2010-08-26 Thread Bill Allen
On Thu, Aug 26, 2010 at 7:44 PM, Corey Richardson  wrote:

> Why don't you try it out without the "from tkinter import ttk" statement,
> and see if it works?
>
> Bill Allen wrote:
>
>> I was experimenting with Tk today, just trying it out.   I found this
>> example of a very simple "hello world" button click program.  This is it.
>>
>> from tkinter import *
>> from tkinter import ttk
>>
>> root = Tk()
>> button = ttk.Button(root, text="Hello World").grid()
>> root.mainloop()
>> What I don't understand is why it is necessary to run that import
>> statement twice.  Shouldn't import * bring everything in from tkinter?
>>
>>
>> Just wondering,
>>
>> Bill Allen
>>
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about import statement

2010-08-26 Thread Bill Allen
I was experimenting with Tk today, just trying it out.   I found this
example of a very simple "hello world" button click program.  This is it.

from tkinter import *
from tkinter import ttk
root = Tk()
button = ttk.Button(root, text="Hello World").grid()
root.mainloop()

What I don't understand is why it is necessary to run that import statement
twice.  Shouldn't import * bring everything in from tkinter?


Just wondering,

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


Re: [Tutor] box drawing characters

2010-08-23 Thread Bill Allen
On Wed, Aug 18, 2010 at 2:13 PM, Bill Allen  wrote:

>
> "Ewald Horn"  wrote in message
>> news:aanlktinmkzyxbd0t7rldyexhbanw1tnfzac5z2gee...@mail.gmail.com...
>>
>>  Hi Bill,
>>>
>>> have you given UniCurses a spin?
>>>
>>> See http://pyunicurses.sourceforge.net/ for more information.
>>>
>>>
>> This does look very interesting and the documentation seems to reflect a
> product that is quite complete.   I will definitely give it a try.
>
> Thanks,
> Bill
>
I did finally have a chance to give this a try.   Seems to work as it
should.   Users should read the installation instructions carefully,
particularly if installing on a Windows system as the additional PDCurses
library (pdcurses.dll) is also required.

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


Re: [Tutor] inserting variables into a docstring

2010-08-21 Thread Bill Allen
On Sat, Aug 21, 2010 at 11:27 PM, Hugo Arts  wrote:

>
> The variable is inserted just fine for me, though there's some
> problems with the  tag, because you shouldn't surround GET
> variables with quotation marks, e.g. you should do this:
>
> http://example.com/?ecn=423434
> NOT this:
> http://example.com/?ecn="423434";
>
> If you do this, the HTML parser will encounter the first ", think that
> it's come to the end of the href="" attribute, and ignore the rest.
> But that's an HTML issue, not a python one.
>
> As an aside, consider using string formatting operations like so:
>
> newMail.HTMLBody = """
> 
> ECN number {0} on Project {1} has been closed.
> Below is a link to the ECN on the intranet.
>  href="http://web_server_at_work.com/cgi-bin/part-url.cgi?ecn={0}
> ">{0}
> ECN Description:
> {2}""".format(pecn, pecn_project, pdesc)
>
>
> Hugo,

Thank you for the reminder of the problem with the HTML.  I see that now.
You are right, however, using that format method works wonderfully and is
definitely the way to go!   I see how I can apply that in lots of ways.

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


[Tutor] inserting variables into a docstring

2010-08-21 Thread Bill Allen
I am trying to build an HTML body text for an email using a docstring with
variables inserted a certain points.  It all works just fine, except that
the first instance of the variable "pecn" in the HTML link does not get
inserted into the text.  The second instance of "pecn" gets inserted ok into
that HTML link.   What is the right way to do this or is there a better way
in general?

This my code:

pecn = "5022543"
pecn_project = "F876540"
pdesc = "some sort of ECN for who knows what reason!"

newMail.HTMLBody = """

ECN number """+pecn+""" on Project """+pecn_project+""" has been closed.
Below is a link to the ECN on the intranet.
http://web_server_at_work.com/cgi-bin/part-url.cgi?ecn=";
"""+pecn+""" "">"""+pecn+"""
ECN Description:
"""+pdesc+"""

ECN Effect of Change Comments:
(still need to work on this part)

R&D Information:
(still need to work on this part)

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


Re: [Tutor] Windows Power Shell

2010-08-21 Thread Bill Allen
The very best first feature to learn is the "foreach" command.  It elegantly
solves the icky, age old, problem in DOS batch of reading in a list of
values from a file and doing something with them.   This alone sold me
completely on WPS.

For instance, here is and actual script I used to push an install source to
all my engineering systems at work, listed in computers.txt, by invoking
richcopy<http://download.microsoft.com/download/f/d/0/fd05def7-68a1-4f71-8546-25c359cc0842/HoffmanUtilitySpotlight2009_04.exe>(also
a fantastic utility, Microsoft's modern replacement for robocopy.

get-content computers.txt | foreach -process {richcopy
"\\myNAS\NasShare\NX6\nx6028" "\\$_\c$\nx6028" /TD 10 /QA /QP
"c:\results.log" /US /UD /UE}

Sorry for taking up additional "non-Python" bandwidth, but I got excited
about being able to contribute something back to the group that I actual
know about!  ;-D

Bill

On Sat, Aug 21, 2010 at 12:21 PM, Bill Allen  wrote:

> Alan,
>
> I have used WPS 1.0 for some time at work to script software installs,
> etc.  It is very powerful and gives full .NET visibility to "DOS" level
> scripts.  In fact, it is a plausible replacement for VB for most
> administrative scripting work in the Windows environment.
>
> Some good resources:
> The Hey Scripting Guy <http://blogs.technet.com/b/heyscriptingguy/>!
> Technet blog is an execellent place to start as he focuses heavily on WPS.
> PowerShell.com <http://powershell.com/cs/> WPS community (you can also
> sign up for really good daily WPS tips sent straight to you email here, I
> recommend these tips!)
> TechNet Learning to Script 
> Center<http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx>,
> focuses on WPS.
>
>
> Bill
>
>
>
>
>
> On Sat, Aug 21, 2010 at 3:20 AM, Alan Gauld wrote:
>
>> A recent windows update delivered the Windows Power Shell to my desktop.
>>
>> I'd heard of this but never used it till now. I've only started playing
>> with it but
>> it is essentially DOS on steroids. It brings Windows users a shell that
>> seems
>> to be very close to Unix shells like Bash in power and flexibility (and
>> scripting
>> language). It's very early days yet, but I wondered if any other tutor
>> members
>> had started using WPS?
>>
>> Some examples of the extra features include regex,  objects, process
>> control,
>> remote invocation, better loop structures etc...
>>
>> Regards,
>>
>> Alan G.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Power Shell

2010-08-21 Thread Bill Allen
Alan,

I have used WPS 1.0 for some time at work to script software installs, etc.
It is very powerful and gives full .NET visibility to "DOS" level scripts.
In fact, it is a plausible replacement for VB for most administrative
scripting work in the Windows environment.

Some good resources:
The Hey Scripting Guy ! Technet
blog is an execellent place to start as he focuses heavily on WPS.
PowerShell.com  WPS community (you can also sign
up for really good daily WPS tips sent straight to you email here, I
recommend these tips!)
TechNet Learning to Script
Center,
focuses on WPS.


Bill




On Sat, Aug 21, 2010 at 3:20 AM, Alan Gauld wrote:

> A recent windows update delivered the Windows Power Shell to my desktop.
>
> I'd heard of this but never used it till now. I've only started playing
> with it but
> it is essentially DOS on steroids. It brings Windows users a shell that
> seems
> to be very close to Unix shells like Bash in power and flexibility (and
> scripting
> language). It's very early days yet, but I wondered if any other tutor
> members
> had started using WPS?
>
> Some examples of the extra features include regex,  objects, process
> control,
> remote invocation, better loop structures etc...
>
> Regards,
>
> Alan G.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] box drawing characters

2010-08-18 Thread Bill Allen
On Wed, Aug 18, 2010 at 12:36 PM, Alan Gauld wrote:

> Looks interesting, a new one for me, thanks for posting.
>
> Alan G.
>
> "Ewald Horn"  wrote in message
> news:aanlktinmkzyxbd0t7rldyexhbanw1tnfzac5z2gee...@mail.gmail.com...
>
>  Hi Bill,
>>
>> have you given UniCurses a spin?
>>
>> See http://pyunicurses.sourceforge.net/ for more information.
>>
>>
> This does look very interesting and the documentation seems to reflect a
product that is quite complete.   I will definitely give it a try.

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


Re: [Tutor] box drawing characters

2010-08-18 Thread Bill Allen
On Wed, Aug 18, 2010 at 3:15 AM, Alan Gauld wrote:

>
> "Bill Allen"  wrote
>
>> I want to be able to create some user interfaces, similar to what you see
>>>
>> in console based programs like Midnight Commander or other TUI type
>> programs
>> that use box drawing characters to create a user interfaces for input and
>> display of information.
>>
>
> This is OK and you can use curses on Linux/Unix systems and something
> like Conio on Windows, but
>
>
>  However, I do want them to be portable to most
>> platforms that Python will run on.
>>
>
> This is much more difficult. Terminals are non portable and neither
> of the libraries above work on the other system. You would probably
> have to build your UI twice. This is one area where real GUIs work
> better than a terminal.
>
> This is good to know.   For my purposes either will be an acceptable option

for me as I am very much in learning mode.   In the endgame, I can always
do an OS detection and load whichever code is appropriate as the duplication
does not bother me much.

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


Re: [Tutor] box drawing characters

2010-08-17 Thread Bill Allen
On Tue, Aug 17, 2010 at 10:00 AM, bob gailer  wrote:

> On 8/17/2010 12:30 AM, Bill Allen wrote:
>
>> I am looking for some guidance about how to best utilize box drawing
>> characters(using unicode?) in as portable a way as possible in Python.  Any
>> good guides out there for this?
>>
>
> Please tell us a bit more about your goals.
>
>
> I want to be able to create some user interfaces, similar to what you see
in console based programs like Midnight Commander or other TUI type programs
that use box drawing characters to create a user interfaces for input and
display of information.   However, I do want them to be portable to most
platforms that Python will run on.  I have actually found much more
information on designing fully graphical GUI interfaces using Tk or Qt or
GTK, but I know the other type is possible.  I suppose I have a preference
for the older console type programs.

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


[Tutor] box drawing characters

2010-08-16 Thread Bill Allen
I am looking for some guidance about how to best utilize box drawing
characters(using unicode?) in as portable a way as possible in Python.  Any
good guides out there for this?

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


  1   2   >