Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Max Zettlmeißl via Tutor
On Mon, Jul 30, 2018 at 3:20 PM, Sunil Tech  wrote:
> Python memory allocation is varying in all these use cases. Please help me
> understand.

CPython is interning small integers and small strings as a form of optimisation.

"The current implementation keeps an array of integer objects for all
integers between -5 and 256, when you create an int in that range you
actually just get back a reference to the existing object."

For integers see https://docs.python.org/2/c-api/int.html for Python 2
or https://docs.python.org/3/c-api/long.html for Python 3.

For strings see https://hg.python.org/cpython/file/3.5/Objects/codeobject.c#l51
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] closing the window through code

2017-10-01 Thread Max Patient
Hi there
i am preparing for a mock exam using python and was wondering if you can help,
my task is to create apassword checker and one of the criteria is to have a 
quit option. i have looked and looked but can't seem to find a bit of code 
allowing to do this!
if there is any way you coild help me it woild be much appreciated 

yours sincerely 
Max Patient

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


[Tutor] Python Questions

2017-07-18 Thread Max Smith
I have some questions about python.



What's the easiest way to learn python currently I'm using google's excersise 
program, I'm just reading and making notes then testing out what I have learnt. 
Since I' need to understand python fully as I've got a exam in Python for my 
GCSE's if you could give me some tips. I'd be excited to hear.



Thanks very Much,

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


[Tutor] Newcomer with organizational questions

2016-05-26 Thread Max Jegers
Hi,


I am a newcomer who asked a first question here at Tutor. Soon I received a
very good answer from a tutor and put an effort to understand it. After
that I wrote a reply with a thank you and a follow-up question, only to
discover that I don’t see a way to send it.


I need to say I did not write to maillist forums before, only to forums
with Post button right there:).



I reread *tutor-**bounces* auto-response, then did some googling and
realized that I may need to subscribe. So I did on Sunday May 22, and the
webpage said: “*Your subscription request has been received, and will soon
be acted upon. Depending on the configuration of this mailing list, your
subscription request may have to be first confirmed by you via email, or
approved by the list moderator. If confirmation is required, you will soon
get a confirmation email which contains further instructions.*”

Main question: Should I wait more or I am missing something I need to do at
my end?

My purpose is to post a reply in a particular subject I initiated.



Please note that I did not receive anything from a tutor in my email other
than *tutor-bounces* auto-response. I use Gmail.



Other organizational questions:

-   -   May I attach a file to a message? Some Python libraries are
quite big (50 pages in my case), however it may be not difficult for an
expert to answer a question if he/she has a full library. At the same time,
it seems inconsiderate and impractical to paste 50 pages into a message.

-   -   Can I paste not in plain text – using fonts etc?

-   -   May I ask a follow-up question in the same thread, or should I
start a new one?

-   -   Is this ok to post a message that contains thank you only, or
these messages have to be deleted by moderators (like on stackoverflow.com?)

I believe first I was able to see a tutor’s response on external website:
https://code.activestate.com/lists/python-tutor/107992/  - and much later
on mail.python.org. Is this persistent behaviour?

Possibly, all this is answered in a document somewhere?



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


[Tutor] What these Python user-defined functions do?

2016-05-21 Thread Max Jegers
Hi,

I started learning Python (v3.5) and was given some code samples to assist
in my studies. There are some things I could not figure out using Python
documentation or other online sources. I have experience with SQL
programming and some procedural programming, but little in terms of OOP.



I try to slice and dice a Python script that exports a shipment from ERP
system to a text file.

Shipment consists of a Header (H, one record) and Details (D, one or more
records).



Script first imports a library with a number of user-defined functions.
Then the script uses functions defined in library to do exporting to a text
file.

Here is the part of the library:


class View:

def __init__(self):

  self.handle = None

…

def order(self, n):

  return hostviewOrder(handle, self.handle, n)



def put(self, fieldName, value, verify=1):

  if verify == True:

 verify = 1

  elif verify == False:

 verify = 0

  return hostviewPut(handle, self.handle, fieldName, value,
verify)



def read(self):

  return hostviewRead(handle, self.handle)



def browse(self, filter="", ascending=1):

  if ascending == True:

 ascending = 1

  elif ascending == False:

 ascending = 0

  return hostviewBrowse(handle, self.handle, filter, ascending)



def fetch(self):

  return hostviewFetch(handle, self.handle)



Here is a part of the script I am trying to understand:

def ExportShipment():

 f = open("c:\\" + me.get("SHN") + ".txt", "w")

 h = View("Header", *1*)

 d = View("Details", *1*)

 h.*order*(1) # SHN

 h.*put*("SHN", me.get("SHN"), 1)

 h.*read*()

 f.write("H," + h.get("LOCATION") + "," + h.get("ADDR1") + "\n")

 d.*browse*("SHIUNIQ=" + "{:.0f}".format(h.get("SHIUNIQ")), 1)

 while (d.*fetch*() == 0):

 f.write("D," + d.get("ITEM") + "," +
"{:.0f}".format(d.get("QTYSHIPPED")) + "\n")

 f.close()



Export output looks like:

H,4,1234 Any Road

D,A2,1

D,B1,3


I understand what file operations do. However I can’t get what these
functions do:

*order(), put(), read(), browse(), fetch()*.


Function definitions in the library are of little help for now, as all
functions feature handle and self.handle in their returns; however I cannot
find out what handle and self.handle may mean in this context.



Please let me know if I should provide more info for my question to make
sense.



Thanks a lot!

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


[Tutor] Using tkinter for cross platform application

2013-09-02 Thread Max Bedacht
Hello;
I'm looking for a quick, if possible, solution to a problem I'm having. I
have developed an application which I'm packaging to run on Windows, Linux
and eventually OS-X. I have gone through myriad iterations, bouncing
between Python 2.7 and 3.3 and between 32 and 64 bit Linux, Windows XP and
Windows 8. At this point I can happily say that everything is working on
all platforms except Apple, which I can not test at this time.

The problem that I am now trying to resolve, which I hope is the last one,
is the following:

When running a packaged 'compiled' version on all windows platforms the
screen, while complete, is reduced by about 20% from the Linux version,
where the development was mostly done. Images seem all to be the same size,
as is the main window, but all of the text, labels and buttons are reduced
in size, not by much, but enough to be annoying. (Curiously, this size
difference does not happen in my development environment (Eclipse/PyDev).
There, if anything, the text in windows seems to be a bit larger than that
in Linux).

I seem to have 3 options at this point:


   1. live with it;
   2. adjust the image portion, which seems fixed in size, to be x% smaller
   in the Windows environment, making the overall window smaller but
   maintaining proportionality;
   3. see if there is a magic bullet to resolve this issue.

Any thoughts would be greatly appreciated.

(Ubuntu 13.04 (64bit), Lubuntu 13.04(32Bit), Windows 8(64Bit), Windows
7(64Bit), Windows XP
Python 2.7 and 3.3 64Bit on the Ubuntu box.
Python 2.7 and 3.3 32Bit on the Windows boxes

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


[Tutor] if statement problems(noob question)

2013-04-08 Thread Max Smith
Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:

def plus(x,y):
if x and y == int or float:
print "The answer is: " + str(x+y)

else:
print "not a number"


plus(2,2)
plus("one","two")

concatenates one and two insted of printing "not a number"

i have tried to simplify by not cheacking for float values an i have also
tried.

def plus(x,y):
if x and y == int or float:
print "The answer is: " + str(x+y)

elif x or y != int or float:
print "not a number"

Am i perhaps missing something with the logic gates?

Any help is greatly appreciated !
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] .py vs .pyc

2012-04-19 Thread Max S.
Then if I understand correctly, I work with .py files and (should) run them
as .pyc files?

On Thu, Apr 19, 2012 at 10:55 AM, Russel Winder wrote:

> On Thu, 2012-04-19 at 10:47 -0400, Max S. wrote:
> > Could anyone tell me why I should use a .pyc file rather than a .py?
>  After
> > doing some research, I have found that a .py file is first precompiled
> and
> > then run, while a .pyc file is already precompiled and is simply run.
>  But
> > unless I'm mistaken, it seems that a .pyc is no faster or better than a
> .py
> > file.  When should I use a .py, and when should I use a .pyc?
>
> pyc files are just internal PVM files.  Although they appear on the
> filestore visible to the programmer, just leave management of them to
> the PVM.  Humans deal only with .py files -- or possibly pyx if you are
> using Cython.
>
> --
> Russel.
>
> =
> Dr Russel Winder  t: +44 20 7585 2200   voip:
> sip:russel.win...@ekiga.net
> 41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
> London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] .py vs .pyc

2012-04-19 Thread Max S.
Could anyone tell me why I should use a .pyc file rather than a .py?  After
doing some research, I have found that a .py file is first precompiled and
then run, while a .pyc file is already precompiled and is simply run.  But
unless I'm mistaken, it seems that a .pyc is no faster or better than a .py
file.  When should I use a .py, and when should I use a .pyc?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extremely simple question

2012-01-11 Thread Max S.
I believe that line 3 raises an error.  The because you contained the text
in single quotes, and then used the same character in 'you're not chris',
Python believes that you are trying to type "you" re not chris".  You can
change the single quotes surrounding your string to double quotes ("you're
not chris"), triple-single quotes ('''you're not chris'''), or
triple-double quotes ("""you're not chris"""), or you can tell Python that
you want to include the apostrophe in your string by preceding it with a \
('you\'re not chris').  The latter works on the same idea as \n and \t.

On Wed, Jan 11, 2012 at 6:04 AM, col speed  wrote:

> 
> > your_weight = int(raw_input("Please enter your weight: "))
> > if your_weight < 0:
> > print 'You're not Chris!'
> > elif your_weight == 170:
> > print 'You might be Chris! But...'
> > your_height = int(raw_input("Please enter your height: "))
> > if your_height < 180:
> > print 'You're not Chris!
> > elif your_height == 180:
> > print 'You're Chris!'
> > your_name = int(raw_input("What is your name? "))
> > elif your_height > 180:
> > print 'You're not Chris!"
> > elif x > 170:
> > print 'You're not Chris!'
> 
> 
>  When I open it, the program says I have a syntax error. Praytell,
> where
>  did
>  I go wrong?n
> I'm a newbie, but I get "NameError" because 'x' is not defined.
> Also "your_name = int(raw_input("What is your name? "))" will give this :
> ValueError: invalid literal for int() with base 10: 'name'.
> As you can't change a string to be an int.
> I can't find a syntax error, but next time, please paste the whole
> traceback as this helps people with less time than me to sort out
> problems.
>
> Good luck with Python
> Col
> ___
> 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] Need Explanation...

2011-12-10 Thread Max gmail

On Dec 10, 2011, at 12:04 PM, Alan Gauld wrote:

> On 10/12/11 16:46, Steven D'Aprano wrote:
> 
>> ...the alternative would also have caught out everybody at some point.
>> Consider a hypothetical Python where mutator methods returned a result:
>> 
>> a = [1, 2, 3]
>> b = a.append(4)
>> 
>> Does this mean...?
>> 
>> * append 4 to a, then return a (and therefore a and b are
>> alternative names for the same list)
> 
> This is what I'd expect.
> I'm thinking about the Smalltalk model where  the default return
> value from a method is self...
> 
> I'm particularly sensitive to this just now because I'm playing
> with Squeak (again) and the elegance and consistency of
> Smalltalk's mechanism  stands in stark contrast to the mixed
> model in Python. (OTOH Smalltalk overall is a frustrating
> experience for me, I would like to love it but never quite
> get there... :-)

Personally, I found that returning a copy of a seemed more logical- after all, 
if you return 4 to b, then adding 2 to b wouldn't make 4 equal 6.
> 
>> circumstances, regardless of which behaviour was choosen for append, it
>> would catch out some people some time.
> 
> Probably, although if returning 'self' were the default (which
> of course only makes sense in a pure OO world like Smalltalk) people would 
> get used to the semantics. Consistency is all in these kinds of situations. 
> Sadly its one of the few areas where Python is slightly inconsistent.
> 
>> A better alternative would be for Python to have procedures as well as
>> functions/methods, so that:
>> 
>> b = a.append(4)
>> 
>> would raise an exception immediately.
> 
> Better than silently returning None for sure.

Of course, by silently returning None, you can just go on with your daily life 
and be happily ignorant of any return value; in other more strongly typed 
languages, the void functions/methods tend to alter other variables and 
situations more than, for example, ints.  I feel myself that it is no more 
trouble to simply type 'a.append(4); b = a'.
> 
> -- 
> 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


Re: [Tutor] beginner here

2011-12-07 Thread Max S.
You are using an 'elif' for your 'coin_rolls == 1:'.  The 'elif' keyword
means that if the last 'if' statement (and any 'elif's behind it) was *not*
true, only then will it be executed.  Your code could be written as 'if
rolls is NOT less than or equal to 100, only then check to see if it is 1
or 2'.  Replace your first 'elif' with 'if', and it should work.

On Wed, Dec 7, 2011 at 8:17 PM, Do youknow who  wrote:

> Im trying to write this program where i make it flip a coin 100 times then
> tells me the number of heads and tails it came up with.
>
> this is what I got but it does not run
>
> # Coin Flip
> # Demonstrating the While loop
> import random
> print("I will flip a coin 100 times and tell you")
> print(", how many heads and how many tails I got.")
> coin_rolls = random.randint(1,2)
> heads = 0
> tails = 0
> rolls = 0
>
> if rolls <= 100:
> rolls += 1
>
> elif coin_rolls == 1:
> heads += 1
> elif coin_rolls == 2:
> tails += 1
> else:
> print("error")
> print("There was ", heads, "rolls for heads,")
> print("\nand there was ", tails, " rolls for tails.")
> input("\n\nPress the enter key to exit.")
>
> I end up with 0 rolls for heads and 0 rolls for tails...I have made
> attempts to put the
> "coin_rolls = random.randint(1,2)" within the loops but only end up with
> errors
> what wrong with my code?
>
> ___
> 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] why doesn't python show error

2011-11-29 Thread Max gmail
In some cases, it is a useful fact that Python only shows error messages when 
they are encountered.  For example, I can test a program while keeping away 
from an area that still doesn't work, rather than having to make it work 
flawlessly before my first test.

Python *can* generate executables with py2exe, though if you use Python 3 
you'll need to learn to convert your code to Python 2.  Or, as Blender does, 
you could include Python in the download of your program, so that the user 
installs both your program and Python.

On Nov 28, 2011, at 4:53 AM, surya k wrote:

> 
> 1. Why doesn't python show error(description given below) at the beginning 
> when we use functions which aren't present in the standard modules...
> 
> Example: 
> 
> TheString = raw_input('enter a string')lengthofStr = strlen(TheString)Look 
> closely, I used a wrong function to find length of the string. [ strlen( ) 
> belongs to C ].When I run the program, it didn't show any error but when 
> entered input, it then showed up!.Why python doesn't show error at the 
> beginning just like C does?2. Why doesn't python create executable file (.exe 
> ) when we run the code.. If this doesn't do, how can I share my program.. 
> does everyone need to have python to check others code and know what it does? 
> 
> ___
> 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] Saving read-only or encoded text files?

2011-11-18 Thread Max gmail
Thank you.  This will work perfectly.

On Nov 18, 2011, at 11:58 AM, Prasad, Ramit wrote:

> Hi.  I've been using a lot of text files recently, and I'm starting to worry 
> about a user hacking some element by editing the text files.  I know that I 
> can pickle my data instead, creating less easily editable (try saying that 
> five times fast) .dat files, but I'd rather store individual variables rather 
> than lists of objects.  Is there a way to make my text files either read-only 
> or saved in some way that they can't be opened, or at least not so easily as 
> double-clicking on them?  I just want some slightly more secure code, though 
> it's not too important.  I just thought I'd ask.
> ==
> 
> Any file will eventually be able to be reverse engineered, but it matters how 
> much effort you care to obfuscate it. The way you can do it will vary based 
> on your OS. 
> 
> For Windows, you can change the file extension to something that is not read 
> by most text editors '.zxy'. It will still be able to be read if they try and 
> open it with a text editor, but double clicking  will not work by default. 
> You can also try setting the file attribute directly: 
> http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/
>  
> 
> For *nix/OS X, you can prepend the file with "." as those files are hidden by 
> default on most *nix systems I have used. You can also try to use 
> os.chmod(0###, 'filename').
> 
> 
> Keep in mind that all of these solutions are probably user reversible since 
> the application will have the permissions of the user account it is run as; 
> in most cases this is the same as the logged in user.
> 
> 
> 
> Ramit
> 
> 
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
> 
> --
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.  
> ___
> 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] Saving read-only or encoded text files?

2011-11-18 Thread Max S.
Hi.  I've been using a lot of text files recently, and I'm starting to
worry about a user hacking some element by editing the text files.  I know
that I can pickle my data instead, creating less easily editable (try
saying that five times fast) .dat files, but I'd rather store individual
variables rather than lists of objects.  Is there a way to make my text
files either read-only or saved in some way that they can't be opened, or
at least not so easily as double-clicking on them?  I just want some
slightly more secure code, though it's not too important.  I just thought
I'd ask.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Encoding

2011-11-18 Thread Max S.
Well, I am assuming that by this you mean converting user input into a
string, and then extracting the numerals (0-9) from it.  Next time, please
tell us your version of Python.  I'll do my best to help with this.  You
might try the following:

the_input = input("Insert string here: ") # change to raw_input in python 2
after = ""
for char in the_input:
try:
char = int(char)
except:
after += char

If other symbols might be in the string ($, @, etc.), then you might use

the_input = input('Insert string here: ') # change to raw_input in python 2
after = ''
not_allowed = '1234567890-=!@#$%^&**()_+,./<>?`~[]{}\\|'
for char in the_input:
if char in not_allowed:
pass
else:
after += char

This method requires more typing, but it works with a wider variety of
characters.  Hopefully this helped.

On Thu, Nov 17, 2011 at 8:45 PM, Nidian Job-Smith wrote:

>
> Hi all,
>
> In my programme I am encoding what the user has in-putted.
>
> What the user inputs will in a string, which might a mixture of letters
> and numbers.
>
> However I only want the letters to be encoded.
>
>
> Does any-one how I can only allow the characters to be encoded ??
>
> Big thanks,
>
>
>
> ___
> 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] sifting through a long program

2011-11-10 Thread Max S.
Alt+G, or Edit>Go To Line.

On Thu, Nov 10, 2011 at 1:58 PM, Nathaniel Trujillo
wrote:

> How do I get to line 362 of a program without counting each line ?  Thanks
> for the help.
> ___
> 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 methods in same class

2011-11-06 Thread Max S.
Oh.  Sorry.  It's 500 lines, so I'll just post an example.  Windows Vista
and Python 3, just because I forgot.

class K:

def __init__(self): doThis()

def doThis(self): print("Hi.")

k = K()


>From what I understand by your help, the code

class K:

def __init__(self): self.doThis()

def doThis(self): print("Hi.")

k = K()

should work.  Thank you for coping with my lack of code to work with.

On Sun, Nov 6, 2011 at 4:23 PM, Peter Lavelle
wrote:

> Hi,
>
> Could you post a copy of the code you are working on, so we can help you
> better with this?
>
> Usually, when calling a method in the same class you use the syntax:
> self.method_name()
>
> 'self' refers to an attribute or method within the same class.
>
> Sorry, if this does not help you.
>
> Regards
>
> Peter Lavelle
> __**_
> 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 methods in same class

2011-11-06 Thread Max S.
Hi.  I'm working on a project for my friend, but I'm running into errors.
No matter what I do, I can't seem to get one method to execute another
method in the same class.  Is there a way that I can do this?  Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Max gmail
Thank you, Wayne!  This helps a lot.
On Nov 4, 2011, at 5:38 PM, Wayne Werner wrote:

> On Fri, Nov 4, 2011 at 4:21 PM, Max S.  wrote:
> Is it possible to create a variable with a string held by another variable in 
> Python?  For example,
> 
> >>> var_name = input("Variable name: ")
> (input: 'var')
> >>> var_name = 4
> >>> print(var)
> (output: 4)
> 
> (Yeah, I know that if this gets typed into Python, it won't work.  It just 
> pseudocode.)
> 
> There are a few ways to do what you want. The most dangerous (you should 
> never use this unless you are 100% absolutely, totally for certain that the 
> input will be safe. Which means you should probably not use it) method is by 
> using exec(), which does what it sounds like: it executes whatever is passed 
> to it in a string:
> 
> >>> statement = input("Variable name: ")
> Variable name: var
> >>> exec(statement + "=4")
> >>> var
> 4
> 
> The (hopefully) obvious danger here is that someone could type anything into 
> this statement:
> 
> >>> statement = input("Variable name: ")
> Variable name: import sys; sys.exit(1); x
> >>> exec(statement + " =4")
> 
> and now you're at your prompt. If the user wanted to do something more 
> malicious there are commands like shutil.rmtree that could do *much* more 
> damage.
> 
> A much safer way is to use a dictionary:
> 
> >>> safety = {}
> >>> safety[input("Variable Name: ")] = 4
> Variable Name: my_var
> >>> safety["my_var"]
> 4
> 
> It requires a little more typing, but it also has the advantage of accepting 
> perfectly arbitrary strings.
> 
> There may be some other ways to do what you want, but hopefully that should 
> get you started.
> HTH,
> Wayne

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


Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Max gmail
Thanks Steven.
On Nov 4, 2011, at 6:45 PM, Steven D'Aprano wrote:

> Max S. wrote:
>> Is it possible to create a variable with a string held by another variable
>> in Python?  For example,
> 
> Yes, but you shouldn't do it. Seriously. Don't do this, you will regret it.
> 
>var_name = input("Variable name? ")  # use raw_input in Python 2
>exec("%s = 4" % var_name)
> 
> 
> Instead, you should use a dictionary, like this:
> 
>var_name = input("Variable name? ")
>table = {var_name: 4}
> 
> and then later when you need to retrieve the value:
> 
>print(table[var_name])
> 
> 
> 
> Why shouldn't you use exec?
> 
> Three main reasons:
> 
> (1) This code contains a MAJOR vulnerability to a code injection attack.   
> There are enough code injection vulnerabilities in the world without you 
> adding to it, please don't add another.
> 
> (2) It makes for hard to read, difficult to follow code.
> 
> (3) It's slow.
> 
> 
> If you don't know what code injection attacks means, consider this simple 
> example where I create a variable spam=4 while executing any code I like:
> 
> >>> var_name = input('Enter the variable name: ')
> Enter the variable name: print(123*456); spam
> >>> exec("%s = 4" % var_name)
> 56088
> >>> spam
> 4
> 
> 
> In this case, executing "print(123*456)" is harmless, but annoying, but it 
> could do *anything* that Python can do (which is pretty much *anything at 
> all*: delete files, send email, take over your computer, anything). Code 
> injection attacks are among the two or three most common methods that viruses 
> and malware operate.
> 
> Sanitising user input so it is safe to pass to exec is a hard job. But 
> suppose you do it (somehow!):
> 
>var_name = sanitise(input('Enter the variable name: '))
>exec("%s = 4" % var_name)
># ...
># ... later on
># ...
>print(spam+1)  # do something useful with the new variable
> 
> But wait, that can't work! How do you know that the variable is called 
> "spam"? You don't. It could be called anything. So now you have to do this:
> 
>exec("print(%s+1)" % var_name)
> 
> which is a nuisance, it is harder to read and harder to follow, and defeats 
> any of the useful features in your editor or IDE. It gets worse if you need 
> to use this var_name repeatedly:
> 
>exec("print(%s+1)" % var_name)
>exec("my_list = [1, 2, 3, %s, 5]" % var_name)
>print(my_list)
>exec("y = func(23, %s, 42) + %s" % (var_name, var_name))
>print(y)
> 
> How tedious and painful and hard to follow. And it is potentially buggy: what 
> if the user typed "func" as the variable name, by accident? Or over-wrote one 
> of your other variables?
> 
> And it's slow. Every time you call exec(), Python has to run a 
> mini-interpreter over the string, analyzing it, splitting it into tokens, 
> compiling it into code that can be executed, and then finally execute it. In 
> general, this is slow: in my experience, running exec("command") is about 10 
> times slower than just running command directly.
> 
> So just avoid using exec. Anytime you think you need exec, you almost 
> certainly do not. And you definitely don't need it for indirect variables! 
> Just use a dictionary instead:
> 
>var_name = input("Variable name? ")
>table = {var_name: 4}
># ...
># ... later on
># ...
>print(table[var_name]+1)
>my_list = [1, 2, 3, table[var_name], 5]
>print(my_list)
>y = func(23, table[var_name], 42) + table[var_name]
>print(y)
> 
> 
> 
> 
> -- 
> 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] Assigning variables with names set by other variables

2011-11-04 Thread Max S.
Is it possible to create a variable with a string held by another variable
in Python?  For example,

>>> var_name = input("Variable name: ")
(input: 'var')
>>> var_name = 4
>>> print(var)
(output: 4)

(Yeah, I know that if this gets typed into Python, it won't work.  It just
pseudocode.)

I'm on a Windows Vista with Python 3.2.2.  Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.7 on Ubuntu 11.10 - Do not unintall

2011-11-01 Thread Max gmail
Heh, yeah.  It's usually a bad idea to do stuff like that (I know a guy 
(Windows) who deleted his OS of his system).

On Nov 1, 2011, at 7:40 PM, Joel Montes de Oca wrote:

> I just discovered that it is a bad idea to complete uninstall Python 2.7 on 
> Ubuntu 11.10. If you do, expect a lot of things not to work, mainly your 
> system. haha
> 
> I just reinstalled Python 2.7 and I hope things are not so bad now when I 
> reboot.
> 
> -- 
> -Joel M.
> 
> ___
> 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] Tutor Digest, Vol 92, Issue 77

2011-10-16 Thread Max S.
On Sun, Oct 16, 2011 at 3:44 PM,  wrote:

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
>
> You can reach the person managing the list at
>tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: Bounded Linear Search (tog...@users.sourceforge.net)
>   2. Re: Can I set LD_LIBRARY_PATH within a .py file?
>  (Albert-Jan Roskam)
>   3. Re: Socket and Ports (Jacob Bender)
>   4. 6 random numbers (ADRIAN KELLY)
>
>
> --
>
> Message: 1
> Date: Sun, 16 Oct 2011 19:04:41 +0200
> From: tog...@users.sourceforge.net
> To: tutor@python.org
> Subject: Re: [Tutor] Bounded Linear Search
> Message-ID: 
> Content-Type: text/plain; charset="ISO-8859-1"
>
> Peter Otten wrote:
>
> > To verify that the algorithm is correct now you could walk through
> > increasingly more complex sample data, which may be possible in this
> case,
> > but rarely ever for an entire script. Instead the common approach is to
> > pick a few samples along with the expected outcomes, feed them to your
> > function and verify that they give the expected output
> >
> > def unique_values(items):
> >...
> >return uniq
> >
> > assert unique_values([42, 42]) == [42]
> > assert unique_values([1, 2, 3, 2]) == [1, 2, 3]
>
> Thanks for the tip and where I was failing to see
>
> Togan
>
>
>
> --
>
> Message: 2
> Date: Sun, 16 Oct 2011 11:25:44 -0700 (PDT)
> From: Albert-Jan Roskam 
> To: Hugo Arts 
> Cc: Python Mailing List 
> Subject: Re: [Tutor] Can I set LD_LIBRARY_PATH within a .py file?
> Message-ID:
><1318789544.84883.yahoomail...@web110709.mail.gq1.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi Hugo,
> ?
> You are absolutely right. Thank you! It took me a lot of reading and
> tinkering to find out that typing the following in the terminal works:
> export LD_LIBRARY_PATH=\path\to\the\lib
> python main.py # contains import to my program + calls to the functions in
> it.
> ?
> I find it strange though, that ctypes.CDLL() does not accept library names
> *with the full path*. In Linux, you could do it, but it seems that all the
> dependencies of the libary in that non-standard location are looked for ONLY
> in that non-standard location.
>
> Cheers!!
> Albert-Jan
>
>
> ~~
> All right, but apart from the sanitation, the medicine, education, wine,
> public order, irrigation, roads, a fresh water system, and public health,
> what have the Romans ever done for us?
> ~~
>
> From: Hugo Arts 
> >To: Albert-Jan Roskam 
> >Cc: Python Mailing List 
> >Sent: Sunday, October 16, 2011 1:22 AM
> >Subject: Re: [Tutor] Can I set LD_LIBRARY_PATH within a .py file?
> >
> >On Sat, Oct 15, 2011 at 9:51 PM, Albert-Jan Roskam 
> wrote:
> >> Hello,
> >> Can I set the LD_LIBRARY_PATH environment variable (on-the-fly) within a
> .py
> >> file?
> >> I would like to use an .so-file that lives in a non-standard location.
> >>
> >> This does not work:
> >> try:
> >> ?? os.environ["LD_LIBRARY_PATH"]? += (":" + path)
> >> except KeyError:
> >> ?? os.environ["LD_LIBRARY_PATH"] = path
> >> Currently, I can only run the program in the terminal:
> >> export LD_LIBRARY_PATH=/home/dude/Desktop/test
> >> python /home/dude/Desktop/testLoadLibLinux.py
> >> This works (yaaayy!), but I'd like to run the .py file directly.
> >> Is this possible? I also don't? like the fact that I can't test the .py
> file
> >> in Idle.
> >> Perhaps a complicating factor is a bug in LD_LIBRARY_PATH
> >> in Linux Ubuntu 10 (the version I'm using):
> >> https://bugs.edge.launchpad.net/ubuntu/+source/xorg/+bug/366728
> >> https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/366728/comments/21
> >> solution:
> >> sudo gedit /etc/X11/Xsession.options
> >> (change "use-ssh-agent" into "no-use-ssh-agent")
> >>
> >> Thank you in advance for your thoughts!
> >>
> >> Cheers!!
> >> Albert-Jan
> >>
> >
> >Alright, I'm not going to pretend to be an expert on this one, a bit
> >of this is speculation and inference from what I know about dynamic
> >linking. In short, I don't think you can modify LD_LIBRARY_PATH on the
> >fly and have it actually work. The reason for this is that the linker
> >runs and finds all the libraries *before* the python process actually
> >starts. So by the time you go and modify the environment, all
> >libraries have already been linked, and your modified variable is
> >never even read by the linker.
> >
> >So the best you can do is write a tiny wrapper to set LD_LIBRARY_PATH
> >and then run y

[Tutor] 'object' class

2011-10-14 Thread Max S.
I have seen classes created with 'class Class_Name:' and 'class
Class_Name(object):'.  I'm using the latter, just in case it has some sort
of method that could be useful that I don't know about, but *are *there any
methods in the 'object' class?  And if so, what are they?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generic For Loop

2011-10-12 Thread Max S.
Thanks!

On Wed, Oct 12, 2011 at 8:56 PM, bob gailer  wrote:

>  On 10/12/2011 8:41 PM, Max S. wrote:
>
>> I've been doing some research into C++, and I've noticed the for loops.
>>  Is there a way to use the C++ version of the loops instead of the Python
>> one?  For example, I believe that the Python syntax would be:
>> for a=1, a < 11, a += 1:
>>print(a)
>> print("Loop ended.")
>> if the 'for' keyword did it's function as in C++, Actionscript, or most
>> other programming languages.  Is there a way to do this?
>>
>
> for i in range(1, 11, 1): # the final 1 can be omitted, as it is the
> default value.
>  loop body
>
> OR
>
> i = 1
> while i < 11:
>  i += 1
>  loop body
>
> Your choice - that's all know of - and the for is easier to read and write
> than the while.
>
> --
> 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] Generic For Loop

2011-10-12 Thread Max S.
I've been doing some research into C++, and I've noticed the for loops.  Is
there a way to use the C++ version of the loops instead of the Python one?
For example, I believe that the Python syntax would be:

for a=1, a < 11, a += 1:
print(a)
print("Loop ended.")

if the 'for' keyword did it's function as in C++, Actionscript, or most
other programming languages.  Is there a way to do this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dict['_find']

2011-02-20 Thread Max Niederhofer
Steven, Alan, Knacktus,

thanks for your help. I was indeed very confused because I thought
'_find' was calling something special instead of just being added to
the dictionary (the confusion stemming from
http://www.python.org/dev/peps/pep-0004/ where find module is
obsolete).

When I ran the code, the error I got was:

max:python max$ python ex40.py
State? (ENTER to quit) > CA
Traceback (most recent call last):
  File "ex40.py", line 22, in 
city_found = cities['_find'](cities, state)
  File "ex40.py", line 8, in find_city
return themap(state)
TypeError: 'dict' object is not callable

Two main mistakes: (1) not including the actual search in the while
loop and (2) wrong parentheses in return themap(state) instead of
return themap[state].

Fixed version which runs:

cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}

def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."

cities['_find'] = find_city

while True:
print "State? (ENTER to quit)",
state = raw_input ("> ")
if not state: break
city_found = cities['_find'](cities, state)
print city_found

Thanks for your help, especially the comments about keeping things
separate and explicit. Now to find out why Zed Shaw thinks this is a
good way of doing it...

Best,
Max

On Sun, Feb 20, 2011 at 9:40 AM, Knacktus  wrote:
> Am 20.02.2011 05:14, schrieb Max Niederhofer:
>
>> Hello all,
>
> Hello Max,
>>
>> first post, please be gentle. I'm having serious trouble finding an
>> alternative for the deprecated find module for dictionaries.
>>
>> The code (from Zed Shaw's Hard Way, exercise 40) goes something like
>> this. Hope indentation survives.
>>
>> cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
>
> I use a naming convention for dicts that has made me very happy on several
> occasion ;-):
> key_to_value, in your case
> state_to_city = {...}
>>
>> def find_city(themap, state):
>>     if state in themap:
>>         return themap[state]
>>     else:
>>         return "Not found."
>>
>> cities['_find'] = find_city
>
> Did you put this entry into the same dictionary as the data on purpose?
> Or is the purpose a kind of dispatch? Something that could be a dict on its
> own, like
> private_function_name_to_function = {'_find': find_city}
> You should try to keep things seperate and explicit.
>>
>> while True:
>>     print "State? (ENTER to quit)",
>>     state = raw_input(">  ")
>>
>>     if not state: break
>>
>> city_found = cities['_find'](cities, state)
>> print city_found
>>
>> My question is - how do I rewrite this using an alternate module given
>> find is deprecated? Grateful for all suggestions or pointers. For
>> reference, I'm using 2.6.1 on darwin.
>>
>> Thanks so much for your help.
>>
>> Best,
>> Max
>>
>> --
>> Dr. Maximilian Niederhofer
>> Founder, Qwerly
>> http://qwerly.com/ | http://qwerly.com/max
>> +44 78 3783 8227
>> ___
>> 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
>



-- 
Dr. Maximilian Niederhofer
Founder, Qwerly
http://qwerly.com/ | http://qwerly.com/max
+44 78 3783 8227
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dict['_find']

2011-02-19 Thread Max Niederhofer
Hello all,

first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.

The code (from Zed Shaw's Hard Way, exercise 40) goes something like
this. Hope indentation survives.

cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}

def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."

cities['_find'] = find_city

while True:
print "State? (ENTER to quit)",
state = raw_input("> ")

if not state: break

city_found = cities['_find'](cities, state)
print city_found

My question is - how do I rewrite this using an alternate module given
find is deprecated? Grateful for all suggestions or pointers. For
reference, I'm using 2.6.1 on darwin.

Thanks so much for your help.

Best,
Max

--
Dr. Maximilian Niederhofer
Founder, Qwerly
http://qwerly.com/ | http://qwerly.com/max
+44 78 3783 8227
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] about import statement

2011-01-10 Thread Max Countryman
On Jan 10, 2011, at 7:58 AM, arun kumar wrote:

> how to know that we
> should import something. How do we know that certain classes are in
> particular module?

You know to import a module if you need part of that module. Perhaps you need a 
class or function defined in the module.

There are several ways to see what a module provides. The documentation is 
usually a good place to start. You can also use dir(), e.g. import foo; 
dir(foo).

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


[Tutor] powerball

2008-06-12 Thread max baseman

hello and thank you everyone for your help.
I apologize for my ignorance when it came to knowledge of what the  
powerball is  it is not as wide spread as i had thought it was


the powerball is a form of lottery their are 5 numbers between 1 and  
55, and then their is the powerball between 1 and 42 players win  
different amounts of money depending on how many numbers they had  
right the program i wrote uses the number 146107962  as the amount of  
tickets in play i found this number on the powerball stat as the  
probability of getting jackpot 1 / 146107962 included is the finished  
and working script if anyone would like to use or play with it.


from random import randrange # for creating random numbers
wins=0 # to see how many people would win
win=[] # the winning numbers go here 
count=0 
for count in range(5): # powerball uses 5 numbers
win.append(randrange(55)+1) 
powerball=randrange(42)+1 
count=0
while count != 146107962: # point of information useing for count in range(146107962) will overlaoad with this large a number 
numbers=[] # guesses
count2=0
for count2 in range(5):
number=randrange(55)+1
if number in win: # if the number is in the winning numbers continue
numbers.append(number) 
else:
print "lose" # else quite while ahead
break
numbers.sort() 
win.sort()
ball=randrange(42)+1 #picks the powerball
if ball == powerball:
print "win"
wins=wins+1
count=count+1
print
print wins,"winners with", win, powerball



seeing as i have left the python mailing list in the past any  
comments or ideas would be appreciated if sent to this email - thank  
you 
   ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] powerball

2008-06-11 Thread max baseman
as a fun little project i scripted a powerball program. it seems to  
have a bug in it that i cant find.


from random import randrange
wins=0
win=[]
count =0
while count !=5:
number=randrange(55)+1
win.append(number)
count=count+1
powerball=randrange(42)+1
count=0
win.sort()
while count !=146107962:
numbers=[]
count2=0
while count2 !=5:
number=randrange(55)+1
if number in win:
numbers.append(number)
else:
print "lose"
break
numbers.sort()
ball=randrange(42)+1
if ball==powerball:
print "win"
print
print
print win, powerball




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


[Tutor] locating python scripts

2008-01-06 Thread max baseman
hey i just have a small question, doesn't have much to do with  
programing but it has to do with python.
anyways Im running a apple computer  version 10.4 and have been  
keeping my scripts in the user folder i was wondering where and how i  
can change the files that python looks in when looking for programs i  
would like to make it so that i can have separate folders in the user  
folder for different projects
any help would be great
thanks 
   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] war cards

2007-12-24 Thread max baseman
hello all, i have been rolling the idea of writing a simple script to  
play the classic card game war. i thought it would be good for me  
because their is no skill in the game. while thinking of how to write  
it i got stuck on one bit, how do i make it so that their is one of  
each card and i can split them?
any help would be great 
   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] another quickie

2007-10-04 Thread max baseman
hello all, im sorry but i might be asking a lot of Tkinter questions  
for a bit.
im still working on my first GUI, it is very simple all i want it to  
do is open a text file, write to it, than save it. so far i have a  
GUI with the ability to right text (nothing amazing), but i don't  
know how to have it display the text from a text file any help would  
be great

from Tkinter import *
top=Tk()
F=Frame(top)
F.pack()
F.txtBox=Text(top)
F.txtBox.pack()
F.pack()

this is all i have so far ^_^" 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter text

2007-10-03 Thread max baseman
sorry, what i was trying to say was, how would i write something that  
at first tries to create a hidden file on a apple computer then if  
the computer was not a apple creates a hidden file on a windows OS

i have slowly been reading your tutorial and it's really one of the  
best tuts i've ever read i really like and that was the first place i  
checked but in the GUI section the text entry bit is for a single  
line of text




On Oct 3, 2007, at 3:58 PM, Alan Gauld wrote:

>
> "max baseman" <[EMAIL PROTECTED]> wrote
>
>> i've got two questions, 1st how would you go about creating a hidden
>> text file that trys on a apple and if that does not work tries to do
>> it on a windows computer?
>
> I don;t undeetabnd this bit. What does the text file try on
> the Apple/Windows computer?
>
>> the program I'm making is a vary simple text editor for one file all
>> it needs to be able to do is add text and save. as far as i can see
>> i'll mostly need to use the text widget but i cant find a tutorial
>> for that widget mostly just for the text entry widget which is only
>> for one line of text. if anyone knows a good tut that would be great
>
> This should only be about 20 lines of code. The Text widget plus
> the standard fole open/save dialogs should dop all you need.
>
> For a very simple example of using the Text widget see the case
> study and the Event Driven programming topics of my tutor.
>
> For more detail see Fred Lundh's Tkinter reference.
>
> When you get stuck ask here.
>
> HTH,
>
>
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] Tkinter text

2007-10-03 Thread max baseman
hello im working on my first simple gui using Tkinter
i've got two questions, 1st how would you go about creating a hidden  
text file that trys on a apple and if that does not work tries to do  
it on a windows computer?

the program I'm making is a vary simple text editor for one file all  
it needs to be able to do is add text and save. as far as i can see  
i'll mostly need to use the text widget but i cant find a tutorial  
for that widget mostly just for the text entry widget which is only  
for one line of text. if anyone knows a good tut that would be great


thank you 

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


[Tutor] quick question

2007-09-24 Thread max baseman
hello just a quickie today :)

how is python with patters or finding a rule for something ie: in out  
tables
for example how hard would it be to write a program that take's a  
input of a in out table and finds the rule

ex:

in  out
10  23
5   13
1   5
0   3

the rule is in*2+3

if possible do you know any tutorials that would help


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


Re: [Tutor] making math problems mmmm fun

2007-09-11 Thread max baseman
lol sorry i was born with bad grammar and hand writing (although it's  
the bit after being born that matters)

On Sep 10, 2007, at 10:41 PM, Eric Brunson wrote:

>
> When you get done with this math problem you should consider a book  
> on punctuation. Not using it makes your sentences run together and  
> difficult to read. :-) Honestly, I just gave up after the first two  
> lines.
>
> max baseman wrote:
>> haha :) yeah it's the new imp stuff i like parts of the idea but   
>> other parts i really dislike basically it TRIES   to make math  
>> more  interactive and world like i really enjoy how most of it is  
>> really  programable stuff :) where compared to normal math books  
>> it's a bit  harder to program just a problem instead of a story  
>> but imp needs  help with it's grading and teaching the grading is  
>> terrible i can get  a A as long as i can explain and know how my  
>> way of doing it wrong  "works" but will fail if i just write the  
>> write answer without  explanation i dont mind the explanations bit  
>> but that what i write  matters more than if i can do the work  is odd
>> adn i just haven't learned anything new yet :)
>>
>> On Sep 10, 2007, at 7:16 PM, wormwood_3 wrote:
>>
>>
>>> Don't have any ideas to Pythonize this problem for you, but I  
>>> must  say that I hope this problem was listed in a chapter  
>>> entitled  "Cruel and Unusual"!
>>>
>>> -Sam
>>> 
>>> - Original Message 
>>> From: max baseman <[EMAIL PROTECTED]>
>>> To: tutor@python.org
>>> Sent: Monday, September 10, 2007 6:28:23 PM
>>> Subject: [Tutor] making math problems  fun
>>>
>>> hello all this is a homework in math i dont need to program it but i
>>> would like to :)  so like any other time pleas  dont just give a
>>> answer tutorials or a explanation. i dont like to use script
>>> something i dont understand :)
>>>
>>> thanks
>>>
>>> basically the problem is to find a bunch of ways to put 1,2,3,4,5
>>> into different math problems to that equal 1-25, i haven't spent to
>>> much time thinking about how to do this but i cant think of a way to
>>> do it it without writing making the program rather long here is the
>>> page from the book for the rules i will be working on this for the
>>> next week or so thanks for any help :)
>>>
>>>
>>>
>>>
>>>   . you may use any of the four basic arithmetic operations-
>>> addition, subtraction, multiplication, and division (according to  
>>> the
>>> order of operations rules). for example, 2+1x3-4 is a 1-2-3-4
>>> expression for the number 1.
>>>
>>> . you may use exponents. for example, 2² - 4 - 1 is a 1234  
>>> expression
>>> for the number 3
>>>
>>> . you may use radicals for EX: √4x2+1 is equal to 3 so 3+√4x2 
>>> +1 is
>>> a 1234 expression for 6
>>>
>>> . you may use factorials for EX: 4! means 4x3x2x1 so 3+4!+1-2 is a
>>> 1234 expression for the number 26
>>>
>>>
>>> . you  may juxtapose two or more digits (that is put them next to
>>> each other) to form a number such as 12. for example 43-12 is a 1234
>>> expression for 31
>>>
>>> . you may use parentheses and brackets to change the meaning of a
>>> expression for example according to the rules of order of  
>>> operations 1
>>> +4x3² is a 1234 expression for 37. you can add parentheses and
>>> brackets to get [(1+4)x3]² which is a 1234 expression for 225
>>>
>>> . must use 1,2,3,4 exactly once
>>>
>>>
>>>
>>> thanks for the help ill post if i find anything
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>

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


Re: [Tutor] making math problems mmmm fun

2007-09-10 Thread max baseman
wow this is a bit over my range of knowledge im impressed :) ill be  
happy to look at it but i think  i will see if i can end up writing  
my own :) worse case ill do it by hand will not take long hmm wow  
thanks :)



On Sep 10, 2007, at 8:47 PM, John Fouhy wrote:


###
import operator

binops = { 'add':operator.add,
   'sub':operator.sub,
   'mul':operator.mul,
   'div':operator.truediv,
   'pow':operator.pow,
   'join':lambda x, y: int(str(x)+str(y))
   }

patterns = { 'add':'(%s) + (%s)',
 'sub':'(%s) - (%s)',
 'mul':'(%s) * (%s)',
 'div':'(%s) / (%s)',
 'pow':'(%s)^(%s)',
 'join':'%s%s'
 }

def combine(digits):
""" digits :: set(int)

output :: [ (value, expression) ]
  value :: int
  expression :: str -- string representation of math expression
"""

# We're going to solve this instance in terms of the solution
# for a list with one fewer digit.

# Because of non-commutativity, we have to do this twice for each
# possible start digit.

res = []

# Base case.
if len(digits) == 1:
return [(digit, str(digit)) for digit in digits]

# Otherwise..
for digit in digits:
remainder = digits - set([digit])

for val, exp in combine(remainder):
for binop in binops:
if binop == 'join':
# Ensure we only join numbers, not expressions.
try:
int(exp)
except ValueError:
continue

try:
newval1 = binops[binop](digit, val)
pattern1 = patterns[binop] % (str(digit), exp)
res.append((newval1, pattern1))
except ZeroDivisionError:
pass

try:
newval2 = binops[binop](val, digit)
pattern2 = patterns[binop] % (exp, str(digit))
res.append((newval2, pattern2))
except ZeroDivisionError:
pass

return res

if __name__ == '__main__':
res = combine(set(range(1, 4)))


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


Re: [Tutor] making math problems mmmm fun

2007-09-10 Thread max baseman
haha :) yeah it's the new imp stuff i like parts of the idea but  
other parts i really dislike basically it TRIES   to make math more  
interactive and world like i really enjoy how most of it is really  
programable stuff :) where compared to normal math books it's a bit  
harder to program just a problem instead of a story but imp needs  
help with it's grading and teaching the grading is terrible i can get  
a A as long as i can explain and know how my way of doing it wrong  
"works" but will fail if i just write the write answer without  
explanation i dont mind the explanations bit but that what i write  
matters more than if i can do the work  is odd
adn i just haven't learned anything new yet :)

On Sep 10, 2007, at 7:16 PM, wormwood_3 wrote:

> Don't have any ideas to Pythonize this problem for you, but I must  
> say that I hope this problem was listed in a chapter entitled  
> "Cruel and Unusual"!
>
> -Sam
> ____
> - Original Message 
> From: max baseman <[EMAIL PROTECTED]>
> To: tutor@python.org
> Sent: Monday, September 10, 2007 6:28:23 PM
> Subject: [Tutor] making math problems  fun
>
> hello all this is a homework in math i dont need to program it but i
> would like to :)  so like any other time pleas  dont just give a
> answer tutorials or a explanation. i dont like to use script
> something i dont understand :)
>
> thanks
>
> basically the problem is to find a bunch of ways to put 1,2,3,4,5
> into different math problems to that equal 1-25, i haven't spent to
> much time thinking about how to do this but i cant think of a way to
> do it it without writing making the program rather long here is the
> page from the book for the rules i will be working on this for the
> next week or so thanks for any help :)
>
>
>
>
>   . you may use any of the four basic arithmetic operations-
> addition, subtraction, multiplication, and division (according to the
> order of operations rules). for example, 2+1x3-4 is a 1-2-3-4
> expression for the number 1.
>
> . you may use exponents. for example, 2² - 4 - 1 is a 1234 expression
> for the number 3
>
> . you may use radicals for EX: √4x2+1 is equal to 3 so 3+√4x2+1 is
> a 1234 expression for 6
>
> . you may use factorials for EX: 4! means 4x3x2x1 so 3+4!+1-2 is a
> 1234 expression for the number 26
>
>
> . you  may juxtapose two or more digits (that is put them next to
> each other) to form a number such as 12. for example 43-12 is a 1234
> expression for 31
>
> . you may use parentheses and brackets to change the meaning of a
> expression for example according to the rules of order of operations 1
> +4x3² is a 1234 expression for 37. you can add parentheses and
> brackets to get [(1+4)x3]² which is a 1234 expression for 225
>
> . must use 1,2,3,4 exactly once
>
>
>
> thanks for the help ill post if i find anything
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] making math problems mmmm fun

2007-09-10 Thread max baseman
hello all this is a homework in math i dont need to program it but i  
would like to :)  so like any other time pleas  dont just give a  
answer tutorials or a explanation. i dont like to use script  
something i dont understand :)

thanks

basically the problem is to find a bunch of ways to put 1,2,3,4,5  
into different math problems to that equal 1-25, i haven't spent to  
much time thinking about how to do this but i cant think of a way to  
do it it without writing making the program rather long here is the  
page from the book for the rules i will be working on this for the  
next week or so thanks for any help :)




  . you may use any of the four basic arithmetic operations-  
addition, subtraction, multiplication, and division (according to the  
order of operations rules). for example, 2+1x3-4 is a 1-2-3-4  
expression for the number 1.

. you may use exponents. for example, 2² - 4 - 1 is a 1234 expression  
for the number 3

. you may use radicals for EX: √4x2+1 is equal to 3 so 3+√4x2+1 is  
a 1234 expression for 6

. you may use factorials for EX: 4! means 4x3x2x1 so 3+4!+1-2 is a  
1234 expression for the number 26


. you  may juxtapose two or more digits (that is put them next to  
each other) to form a number such as 12. for example 43-12 is a 1234  
expression for 31

. you may use parentheses and brackets to change the meaning of a  
expression for example according to the rules of order of operations 1 
+4x3² is a 1234 expression for 37. you can add parentheses and  
brackets to get [(1+4)x3]² which is a 1234 expression for 225

. must use 1,2,3,4 exactly once



thanks for the help ill post if i find anything
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] making math problems mmmm fun

2007-09-10 Thread max baseman
hello all this is a homework in math i dont need to program it but i  
would like to :)  so like any other time pleas  dont just give a  
answer tutorials or a explanation. i dont like to use script  
something i dont understand :)

thanks

basically the problem is to find a bunch of ways to put 1,2,3,4,5  
into different math problems to that equal 1-25, i haven't spent to  
much time thinking about how to do this but i cant think of a way to  
do it it without writing making the program rather long here is the  
page from the book for the rules i will be working on this for the  
next week or so thanks for any help :)




  . you may use any of the four basic arithmetic operations-  
addition, subtraction, multiplication, and division (according to the  
order of operations rules). for example, 2+1x3-4 is a 1-2-3-4  
expression for the number 1.

. you may use exponents. for example, 2² - 4 - 1 is a 1234 expression  
for the number 3

. you may use radicals for EX: √4x2+1 is equal to 3 so 3+√4x2+1 is  
a 1234 expression for 6

. you may use factorials for EX: 4! means 4x3x2x1 so 3+4!+1-2 is a  
1234 expression for the number 26


. you  may juxtapose two or more digits (that is put them next to  
each other) to form a number such as 12. for example 43-12 is a 1234  
expression for 31

. you may use parentheses and brackets to change the meaning of a  
expression for example according to the rules of order of operations 1 
+4x3² is a 1234 expression for 37. you can add parentheses and  
brackets to get [(1+4)x3]² which is a 1234 expression for 225

. must use 1,2,3,4 exactly once



thanks for the help ill post if i find anything 
  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] checking if a number is evan or odd

2007-09-04 Thread max baseman
cool thanks thats what i changed it to than just now i changed to do  
something else and instead of leaving the program running for 4 or 5  
days as i had been i got my answer in less than a second ^_^"

i realized that i was wasting way to much time checking every  
possible answer because the number is jumping around so much so  
instead i wrote a real quick program infact  i wrote it in  
interactive that just starts at 1 and works the problem backwards for  
how ever long i tell it to :))

thanks for considering the homework, but this time you did'nt have to  
worry i did the homework last week i was just doing this for fun, it  
randomly asked something like "what about a number that takes 100  
steps to get to 1" and i thought what about 1000 :)) now i have one  
running looking for a number that takes 100 steps unfortunately i  
dont think ill get any extra credit for doing any of this lol


here is the program sorry copying it from interactive:

 >>> number=1
 >>> count=1000
 >>> count=0
 >>> while count < 1000:
... if (number*2)%2 == 0:
... number=number*2
... else:
... number=(number-1)/3.0
... count=count+1
... print number



On Sep 4, 2007, at 3:00 AM, Alan Gauld wrote:

> Max,
>
>> just wondering if theirs a way to check if a larger number is even
>> or
>> odd
>
> I notice this is homework so I won't give a direct answer.
> But look at the mod operator '%'  - It returns the remainder
> of an integer division. An even number is exactly divisible
> by 2.
>
> HTH,
>
> Alan G.
>
> "max baseman" <[EMAIL PROTECTED]> wrote
>
>> about before ive let it sit for a few days now and i reached a
>> number
>> to high to convert to a decimal by adding 0.0
>
> Thats a terrible way to convert to a float. Just use the float
> function
> (actually a type):
>
> f = float(anInt)
>
> But to determine if its odd/even you don't need to use floats at all.
>
>
>> here's the program:
>>
>> count=1
>> numstart=268549802
>> number=0
>> high=0
>> a=0
>> while 1==1:
>> numstart=numstart+1
>> number=numstart
>> count=1
>> while number !=1:
>> if number/2 == (number+0.0)/2:
>> number=number/2
>> else:
>> number=(number*3)+1
>> count=count+1
>> if count > a:
>> a=count
>> print numstart,":",count
>
>
> Hmm, I have no idea what this is doing...
>
>>
>> thanks
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] checking if a number is evan or odd

2007-09-03 Thread max baseman
cool thanks
the problem was from a math book imp 1 but i already did the work i  
was just interested in what number had the most steps i could fin  
wanted to get to 1000 imagine how dismayed i was when it crashed at 965

On Sep 3, 2007, at 8:23 PM, Andrew James wrote:

> I'd just go with
>
> if number%2 == 0:
>number = number/2
>
> Why do you need to convert it to a float?
>
> Off topic:
> Is this a PE problem? I remember doing the same thing.
>
> max baseman wrote:
>> hello just a quick check in, it's about the same program i was  
>> asking  about before ive let it sit for a few days now and i  
>> reached a number  to high to convert to a decimal by adding 0.0
>> here's the program:
>>
>> count=1
>> numstart=268549802
>> number=0
>> high=0
>> a=0
>> while 1==1:
>>  numstart=numstart+1
>>  number=numstart
>>  count=1
>>  while number !=1:
>>  if number/2 == (number+0.0)/2:
>>  number=number/2
>>  else:
>>  number=(number*3)+1
>>  count=count+1
>>  if count > a:
>>  a=count
>>  print numstart,":",count
>>
>>
>> after a few days i got this error:
>>
>> Traceback (most recent call last):
>>File "homework6high.py", line 11, in 
>>  if number/2 == (number+0.0)/2:
>> OverflowError: long int too large to convert to float
>>
>> just wondering if theirs a way to check if a larger number is even  
>> or  odd
>>
>> thanks
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>

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


[Tutor] checking if a number is evan or odd

2007-09-03 Thread max baseman
hello just a quick check in, it's about the same program i was asking  
about before ive let it sit for a few days now and i reached a number  
to high to convert to a decimal by adding 0.0
here's the program:

count=1
numstart=268549802
number=0
high=0
a=0
while 1==1:
 numstart=numstart+1
 number=numstart
 count=1
 while number !=1:
 if number/2 == (number+0.0)/2:
 number=number/2
 else:
 number=(number*3)+1
 count=count+1
 if count > a:
 a=count
 print numstart,":",count


after a few days i got this error:

Traceback (most recent call last):
   File "homework6high.py", line 11, in 
 if number/2 == (number+0.0)/2:
OverflowError: long int too large to convert to float

just wondering if theirs a way to check if a larger number is even or  
odd

thanks

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


Re: [Tutor] clearing a text document

2007-08-30 Thread max baseman
thats what it does but in order to just be able to let it sit and  
work for as long as it can i made it a endless loop of just trying  
every number, for now it just displays the highest on the screen but  
it would be nice to get it in a text document

thanks

On Aug 30, 2007, at 4:53 AM, Kent Johnson wrote:

> max baseman wrote:
>> right it's for a quick math "game" the rules are simple you start   
>> with any number to get the next number you, a. if it's odd  
>> multiply  by 3 than add 1 or b. if it's even divide by two,  the  
>> point of this  is to see how long it takes to get to one are it  
>> starts to repeat  4,2,1,4,2,1...
>> now im looking for a a number with  a very high amount of numbers   
>> till you get to 1 so every time it's finds a new one i would like  
>> it  to write that to a file and clear the last entry,
>
> If your goal is to find long sequences why not write your program  
> to try every number up to some limit and find the longest?
>
> It's a nice use of generators, for those who know what they are...
>
> These sequences are known as hailstone numbers. The (unproven)  
> conjecture that the sequence will always terminate is called  
> Collatz' Conjecture. Some interesting info and pictures here:
> http://sprott.physics.wisc.edu/pickover/hailstone.html
> http://mathworld.wolfram.com/CollatzProblem.html
>
> Kent

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


Re: [Tutor] clearing a text document

2007-08-30 Thread max baseman
cool thank you :)


On Aug 29, 2007, at 11:02 PM, Luke Paireepinart wrote:

> max baseman wrote:
>> right it's for a quick math "game" the rules are simple you start   
>> with any number to get the next number you, a. if it's odd  
>> multiply  by 3 than add 1 or b. if it's even divide by two,  the  
>> point of this  is to see how long it takes to get to one are it  
>> starts to repeat  4,2,1,4,2,1...
>> now im looking for a a number with  a very high amount of numbers   
>> till you get to 1 so every time it's finds a new one i would like  
>> it  to write that to a file and clear the last entry,
> Just open the file for writing and it will erase all previous  
> contents and create the file if it doesn't already exist.
> -Luke

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


Re: [Tutor] clearing a text document

2007-08-29 Thread max baseman
right it's for a quick math "game" the rules are simple you start  
with any number to get the next number you, a. if it's odd multiply  
by 3 than add 1 or b. if it's even divide by two,  the point of this  
is to see how long it takes to get to one are it starts to repeat  
4,2,1,4,2,1...
now im looking for a a number with  a very high amount of numbers  
till you get to 1 so every time it's finds a new one i would like it  
to write that to a file and clear the last entry,


On Aug 29, 2007, at 5:45 PM, Alan Gauld wrote:

>
> "max baseman" <[EMAIL PROTECTED]> wrote
>
>> quick question how would i clear a text document?
>
> A bit of context? If its a file you just open the file for writing.
>
> If its a list of strings in memory
>
> text = []
>
> will clear it...
>
> If its a GUI text widget it will depend on which framework you are
> using.
>
> Alan G
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] clearing a text document

2007-08-29 Thread max baseman
quick question how would i clear a text document? 
  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] the and command

2007-08-24 Thread max baseman
thanks much you really helped me if anyone wants here is the program:

n2=2
n3=3
n4=4
n5=5
n6=6
n7=7
l2=[]
l3=[]
l4=[]
l5=[]
l6=[]
l7=[]
while n2 < 1000:
 l2.append(n2)
 n2=n2+2
while n3 < 1000:
 l3.append(n3)
 n3=n3+3
while n4 < 1000:
 l4.append(n4)
 n4=n4+4
while n5 < 1000:
 l5.append(n5)
 n5=n5+5
while n6 < 1000:
 l6.append(n6)
 n6=n6+6
while n7<1000:
 l7.append(n7)
 n7=n7+7
possible=[]
for num in l2:
 if num in l3 and num in l4 and num in l5 and num in l6:
 possible.append(num)
for a in possible:
 if a+1 in l7:
 print a+1



On Aug 24, 2007, at 1:25 AM, Alan Gauld wrote:

>
> "max baseman" <[EMAIL PROTECTED]> wrote
>> im checking if a number is in all 5 of the other lists and when
>> i use the and command it seems to just be checking if it's in a
>> least
>> one of the others,
>
>
>> for num in l2 and l3 and l4 and l5 and l6: # here seems to be the
>
> Try:
>
> if num in I2 and num in I3 and num in I4 and num in I5 and num in I6:
>
> In your case you are 'and'ing the lists which is a boolean expression
> and because of how Python does short circuit evaluation it returns
> the last list
>
>>>> a = [1,2]
>>>> b = [3,4]
>>>> a and b
> [3, 4]
>
> so
>
> for n in a and b:
>
> is the same as
>
> for n in b:
>
> which iterates over b...
>
> HTH,
>
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] the and command

2007-08-23 Thread max baseman
hello im checking if a number is in all 5 of the other lists and when  
i use the and command it seems to just be checking if it's in a least  
one of the others, here is the program  it's choppy i needed it for a  
quick calculation so it's not pretty but it's not long:

n2=2
n3=3
n4=4
n5=5
n6=6
n7=7
l2=[]
l3=[]
l4=[]
l5=[]
l6=[]
l7=[]
while n2 < 100:
 l2.append(n2)
 n2=n2+2
while n3 < 100:
 l3.append(n3)
 n3=n3+3
while n4 < 100:
 l4.append(n4)
 n4=n4+4
while n5 < 100:
 l5.append(n5)
 n5=n5+5
while n6 < 100:
 l6.append(n6)
 n6=n6+6
while n7<100:
 l7.append(n7)
 n7=n7+7
possible=[]
for num in l2 and l3 and l4 and l5 and l6: # here seems to be the  
problem
 possible.append(num)
for a in possible:
 if a-1 in l7:
 print a







any help is great thanks

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


[Tutor] web browser

2007-07-21 Thread max baseman
has anyone ever written a web browser with python and Tkinter? if so  
is there any documentation on it? if not does anyone know if their  
which tutorials i should read if i wanted to write one for my apple?

i don't know vary much Tkinter so i was going to start there
then i thought i would be using the urllib and urllib2 modules which  
i know a little about
know i don't know how i would display the html i can get the html of  
any site with urllib but how to show it in Tkinter?

if anyone knows of tutorials for any of those, or has any ideas thank  
you
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] curses

2007-07-16 Thread max baseman
hello all sorry to bother I'm working on my first curses program ive  
been wanting to learn curses for a while now and now that a have a  
lop top with fedora core running in run level 3 ware im trying to  
program all the tools i'll use but curses will be my only gui ALAN  
has been helping me with this program

import curses
from time import sleep
scr=curses.initscr()
population=0
seconds=0
try:
 scr.nodelay(1)
 scr.leaveok(0)
 max_y, max_x = scr.getmaxyx()
 while 1:
 sleep(1)
 second=seconds=+1
 population=population+2.5
 scr.addstr(0,0,"seconds",seconds)
 scr.addch,max_y/2, max_x/2, str(population)[0]
 scr.refresh()
finally:
 curses.endwin()


depending on ware i run this i get different results on may mac OSX  
10.4 i only get a wired second thing in the top left corner that  
looks like this secooes

and when i run this on fedora core 6 i get the seconds word in top  
left but no number and i get a single digit in the midle that changes  
i think the single digit is part of population but not all i cant  
find out what is wrong


any help would be great :)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reading random line from a file

2007-07-14 Thread max baseman
im writing a quick quote reader that spits out a random quote from a  
show but cant get it to pick randomly
i tried
a=randrange(820)+1
text.readline(a)

and i would prefer not having to bring evryline into the program then  
picking like

for line in text.readlines():
lines.append(text)

...



any help would be great thanks 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] curses

2007-07-14 Thread max baseman
hello all sorry to bother I'm working on my first curses program ive  
been wanting to learn curses for a while now and now that a have a  
lop top with fedora core running in run level 3 ware im trying to  
program all the tools i'll use but curses will be my only gui ALAN  
has been helping me with this program

import curses
from time import sleep
scr=curses.initscr()
population=0
seconds=0
try:
 scr.nodelay(1)
 scr.leaveok(0)
 max_y, max_x = scr.getmaxyx()
 while 1:
 sleep(1)
 second=seconds=+1
 population=population+2.5
 scr.addstr(0,0,"seconds",seconds)
 scr.addch,max_y/2, max_x/2, str(population)[0]
 scr.refresh()
finally:
 curses.endwin()


depending on ware i run this i get different results on may mac OSX  
10.4 i only get a wired second thing in the top left corner that  
looks like this secooes

and when i run this on fedora core 6 i get the seconds word in top  
left but no number and i get a single digit in the midle that changes  
i think the single digit is part of population but not all i cant  
find out what is wrong


any help would be great :) 
  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] curses

2007-07-12 Thread max baseman
ok after reading a few tutorials i think i know enough to write my  
program
here it  is
not commented yet though sorry:

import curses
from time import sleep
scr=vurses.initscr()
population=0
seconds=0
try:
scr.nodelay(1)
scr.leaveok(0)
max_y, max_x = scr.getmaxyx()
while scr.getch()== -1:
sleep(1)
seconds=seconds+1
population=population+2.5
scr.addstr(0,0,"seconds:",seconds")  # i would like to get this  
bottom left but didn't know how
scr.sddch(1,0,population) # here is ware i think I'm having problems  
also would like this to be centered
scr.clear()
scr.refresh()
finaly:
curses.endwin()




but i get the error:

traceback (most recent call last):
  file "population.py", line 15, in 
scr.addch(1,0,population)
TypeError: argument 1 or 3 must be a ch or an int



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


[Tutor] curses

2007-07-11 Thread max .

hello all sorry but i just cant seem to get my head around curses iv read a
few of the tuts out there and get what there saying but i cant write my own
if any one can point me in the right direction easer is better i only need
something very simple right now just writting and refreshing

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


Re: [Tutor] writing over text

2007-07-10 Thread max .

thank you so much :)

On 7/10/07, Bob Gailer <[EMAIL PROTECTED]> wrote:


max . wrote:
> hello i am writing a population script and was wondering  if i can
> just keep writing to the same line instead of printing a new line
> every second
import time
for i in range(5):
 print chr(13), i,
 time.sleep(1)

# chr(13) = carriage return, and the trailing , suppresses the newline.

--
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC



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


[Tutor] writing over text

2007-07-10 Thread max .

hello i am writing a population script and was wondering  if i can just keep
writing to the same line instead of printing a new line every second






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


[Tutor] backslashes

2007-07-08 Thread max .

hello i am writing a simple password tester that uses a word list and am
running into some problems when i read the words from a text file they are
written to the screen with a backslash at the end and i cant seem to find a
way to get rid of them

here is the script:

__name__="dictionary password tester"
__author__="max baseman ([EMAIL PROTECTED])"
__version__="0.1"
__discription__="tests a password against a dictonary"
#

print
print
password=raw_input("password >")
passlist=open("/Users/max/passlist.rtf","r") # passlist is just a list of
50,000 words
guesses=0
for line in passlist:
   line=line.replace('\ ','') #heres what i was trying now
   guesses=guesses+1
   line=line.lower()
   print line
   if line==password:
   print
   print
   print"you password was",line,"and it took",guesses,"guesses"
   break





p.s i am about to look up how to type to python and not show the text for
the password bit but if anyone knows please explain
any help would be great thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python port scanner

2007-06-27 Thread max .

thanks evryone for your help am starting on the project :)

On 6/25/07, János Juhász <[EMAIL PROTECTED]> wrote:



Dear dos,

>>hello i am looking into writing a simple python port scanner but i cant
find
>>any good tutorials online if anyone can help or knows of any tutorials
that
>>could help it would be great. this would be my first program like this
so i
>>might need a little extra help

I just recommend to take a look on twisted
http://www.oreilly.com/catalog/twistedadn/
It is a nice book.

There is an example on how to do it with twisted among the examples in
chapter 2.


You can read it on safari.

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


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


[Tutor] python port scanner

2007-06-24 Thread max .

hello i am looking into writing a simple python port scanner but i cant find
any good tutorials online if anyone can help or knows of any tutorials that
could help it would be great. this would be my first program like this so i
might need a little extra help


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


[Tutor] html links

2007-05-14 Thread max .

does anyone know of a tutorial for finding links in a web site with python.

or creating files and asking ware to create a file.

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


[Tutor] web spider

2007-05-13 Thread max .

hello i am a beginner programmer and i am planning a project that will take
a keyword enter that in google and start searching through links ans saving
web pages

if anyone can help or might know of any tutorials about:

writing to websites
searching links
creating files
and web spiders in general that would be great


thanks for any help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2007-01-19 Thread Max Jameson
I know this is totally off-the-wall, but what am I doing wrong here?  I am 
using Python 2.5, and I am just learning...please be kind!


>>> aList = [2,3]
>>> bList = [5,7,9]
>>> aList.append(bList)
>>> print aList
[2, 3, [5, 7, 9]]
>>> print aList [1] [2]
Traceback (most recent call last):
  File "", line 1, in 
print aList [1] [2]
TypeError: 'int' object is unsubscriptable
>>> print aList [0] [1]
Traceback (most recent call last):
  File "", line 1, in 
print aList [0] [1]
TypeError: 'int' object is unsubscriptable
>>>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] winsound mac

2006-11-10 Thread max .
i am starting a small useless program i got from the show lost but cant find 
a module on mac to make beeping noises i know windows has winsound *never 
used it but heard about it* but eather way is thair anything like winsound 
for mac



^_^"  s33 y4

_
Add a Yahoo! contact to Windows Live Messenger for a chance to win a free 
trip! 
http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline

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


[Tutor] embedding python

2006-10-08 Thread max .
hello i have a myspace and a blog both of wich allow me to input html and i 
know a little html not much i can make a page with backround coler a title 
words and pictures as well as links

but i cant find any tutorials on embedding python useing html i found some 
that use c++ and i think one that used asp

if anyone knows how or knows of a tutorial that would be great



^_^"  s33 y4

_
Share your special moments by uploading 500 photos per month to Windows Live 
Spaces  
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://www.get.live.com/spaces/features

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


[Tutor] Tkinter and python

2006-10-08 Thread max .
first off i just started looking for Tkinter tutorials but havent found much 
and what i have found was not very good if anyone knows og any Tkinter 
tutorials pleas let me know


second is thair anyway to change the path that python looks for a program in 
ex: if i enter python hello into the command line then i get this error


/Library/Frameworks/Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/Python: 
can't open file 'hello1': [Errno 2] No such file or directory


can i chage that search path?
if so how?

thx



^_^"  s33 y4

_
Search—Your way, your world, right now!  
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-us&FORM=WLMTAG


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


[Tutor] opening files

2006-09-25 Thread max .
hello i cant understand how to open text files with python
i have tried tutorials and evrything i just cant get pleas help
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reading files

2006-09-22 Thread max .
i cant understand the open command i tried the help command but still
dont get i am trying to write twi programs one to keep track of money
phone numbers... and another to randomly print a statmint from a file

pleas dont just send a program i would like it if you could explain
the command so that i dont have to keep bothering you :P
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Setting a global variable on class initialisation

2006-04-28 Thread Max Russell



Hello 
again
 
Sorry I didn't make 
the problem I'm working with all too clear. Basically I'm working with a class 
(Directory) that upon creation reads in a 3 files and from these files populates 
one main list.
This bit is 
fine.
 
The trickier bit was 
that I need to use two of the sublists (e.g the contents of two of the files) 
outwith the module. I didn't want to read the lists in again as I wanted the 
data to be set at the time the Directory class is created. The lists are 
accessed from other classes and although I tried passing the instance of 
Directory into the new class (Item) but this was causing real problems Item 
was trying to read in the lists:
def __init__(self, 
filename, **args):
I noted that I 
couldn't put my argument for an instance of Directory after **args (presumably 
because **args is used to mop up the remaining arguments as a list) and when I 
put it before it messed up the reading of the list.
 
 
So my code now has 
this format-
 
    
def GetCategories(self):    
#Assign the list values read in via platformCategories and 
typeCategories    global 
platformCategories    
platformCategories = 
self.GetPlatformsFile()    global 
typeCategories    typeCategories = 
self.GetTypesFile()
 
The method above is 
within Directory and updates the two lists with the values I need. (The methods 
called within GetCategories do the returning of the lists.)
 
I think I've got a 
grasp on what was going wrong.
 
ta
 
Max 
RussellSenior 
Test Engineer 
BarcoBonnington 
Bond, 2 Anderson Place, Edinburgh EH6 5NP, UKTel + 44 (0) 131 472 5731 Fax + 
44 (0) 131 472 4799www.barco.com[EMAIL PROTECTED]Unless 
indicated otherwise, the information contained in this message is privileged and 
confidential, and is intended only for the use of the addressee(s) named above 
and others who have been specifically authorized to receive it. If you are not 
the intended recipient, you are hereby notified that any dissemination, 
distribution or copying of this message and/or attachments is strictly 
prohibited. The company accepts no liability for any damage caused by any virus 
transmitted by this email. Furthermore, the company does not warrant a proper 
and complete transmission of this information, nor does it accept liability for 
any delays. If you have received this message in error, please contact the 
sender and delete the message. Thank you. 
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Setting a global variable on class initialisation

2006-04-27 Thread Max Russell



Hello-
 
I know that overall 
Global variables are  bad idea, however, I have a situation where on on 
initialisation of a class, I need to read in two files and then populate two 
lists.
The lists need to 
would appear to need to be outwith the class I am working with and 
global.
 
Can anyone give good 
examples of this?
 
thanks
 
Max 
RussellSenior 
Test Engineer 
BarcoBonnington 
Bond, 2 Anderson Place, Edinburgh EH6 5NP, UKTel + 44 (0) 131 472 5731 Fax + 
44 (0) 131 472 4799www.barco.com[EMAIL PROTECTED]Unless 
indicated otherwise, the information contained in this message is privileged and 
confidential, and is intended only for the use of the addressee(s) named above 
and others who have been specifically authorized to receive it. If you are not 
the intended recipient, you are hereby notified that any dissemination, 
distribution or copying of this message and/or attachments is strictly 
prohibited. The company accepts no liability for any damage caused by any virus 
transmitted by this email. Furthermore, the company does not warrant a proper 
and complete transmission of this information, nor does it accept liability for 
any delays. If you have received this message in error, please contact the 
sender and delete the message. Thank you. 
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Non type object?

2006-03-01 Thread Max Russell
""    Log the script output to a file - echo to the console.        @param  linesToLog List of strings to write out
    """        # if we have a output file write to it    if self._outputFileName != None:    outputFile = open(self._outputFileName, "a")    
    if len(linesToLog) == 0:    outputFile.write("\n")        for line in linesToLog:    outputFile.write(line + "\n")    
    outputFile.close()        # output to shell    if len(linesToLog) == 0:    print     for line in linesToLog:    print line##
#MAIN SECTION##if __name__ == "__main__":    checker = HeaderChecker(sys.argv[1], sys.argv[2], sys.argv[3])        pythonFileList = checker.getValidPythonFiles
()    checker.log([])    checker.log(pythonFileList)        #For all files in the list of Python files, strip the files of the header    #comments markings    changes = []    for text in checker._txtFileList:
    file1 = checker.getFileNameFromPath(text)    for pyfile in pythonFileList:    file2 = checker.getFileNameFromPath(pyfile)    print "comparing %s to %s"%(file1[:-4], file2[:-3])
    if file1[:-4] == file2[:-3]:    print "matched %s to %s"%(file1[:-4], file2[:-3])    pytostrip = checker._directoryToCheck + "\\" + file2    print pytostrip
    stripped = checker.stripFile(pytostrip)    print stripped    #print "\n" + stripped + "\n"    diff =checker.compStripToTxt(text, stripped)
    print diff    if diff:   # changes.append(diff)    print changes    break        Now, I have a lot of print statements in there for debugging purposes, but I don't understand why when I run it, and it parses through my input directory and comparison directory it returns this
NonecompStripToTxt is executedTraceback (most recent call last):  File "HeaderChecker.py", line 182, in ?    diff =checker.compStripToTxt(text, stripped)  File "HeaderChecker.py", line 114, in compStripToTxt
    stripped = open(strippedfile, "r")TypeError: coercing to Unicode: need string or buffer, NoneType foundWhy is it returning the None type?How can I fix this?
thanksMax-- Max RussellSenior Test Engineer BarcoBonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UKTel + 44 (0) 131 472 5731 Fax + 44 (0) 131 472 4799
www.barco.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mamelauncher (fwd)

2005-09-13 Thread Max Russell
There actually seems to be a bit of a problem in the
interaction with the system when it launches mame.

If I run this:

import os

def run_mame_selection(selection):
os.system("C:\\mame096b\\mame.exe"+ selection)
  
#main
selection = " tnzs"
run_mame_selection(selection)
raw_input()

mame reports files missing, but I can launch the game
manually- I suspect that this is some sort of error
that occurs normally but is bypassed on launch and
that  my one-shot attempt to launch the thing cannot
handle. I think I need to have a wee look at
subprocess!

ta

Max

--- Danny Yoo <[EMAIL PROTECTED]> wrote:

> > Also, does this work?
> >
> > ##
> > def run_packman():
> > os.system("C:\\mame096b\\mame.exe packman")
> ^^^
> 
> Gaaa.  My apologies: that was a typo.  Correct this
> (and other places
> where I wrote 'packman') with whatever name you use
> to explicitly tell
> MAME to run PacMan.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




___ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mamelauncher

2005-09-12 Thread Max Russell
I've tried running that function, with a little Main
method like this:

import os

def run_mame_selection(selection):
os.system("C:\\mame096b\\mame.exe"+""+selection)

#main
mine = "pacman"
run_mame_selection(mine)

What I get is like a brief flash of the CMD prompt
like it is trying it and not waiting or getting some
kind of return.

I'm really not sure where I'm going wrong at all! I'll
try re-writing using sub-process as I've upped my
Python to 2.4.


--- Danny Yoo <[EMAIL PROTECTED]> wrote:

> 
> 
> On Fri, 9 Sep 2005, Max Russell wrote:
> 
> > I've been working on this for ages and am having
> real problems with
> > getting the wiring for a selected game to launch
> when I click OK.
> >
> > I haven't added my error handling yet.
> 
> [code cut]
> 
> 
> Hi Max,
> 
> Hmmm... Out of curiosity, what happens if you try
> doing it without the
> GUI?
> 
> Let's try to isolate the problem; it's not clear at
> the moment if there's
> something weird with the GUI, or if there's
> something weird with the
> os.system() call.
> 
> If you can write a quick test case that calls
> os.system() in the same way,
> then we can be more sure what's causing the problem.
> 
> 
> I see that you have a function called launchmame:
> 
> def launchmame(self, event):
> selection = self.lstbx.curselection()
>
> os.system("C:\\mame096b\\mame.exe"+""+selection)
> 
> (Ah.  I do see a possible problem here, but I want
> YOU to see it too.
> *grin*)
> 
> 
> 
> Try testing out the function:
> 
> ##
> def run_mame_selection(selection):
> os.system("C:\\mame096b\\mame.exe"+""+selection)
> ##
> 
> It's mostly a copy and paste of what you had in
> launchmame, except that we
> explicitly pass in the selection string.  But try it
> out with a hardcoded
> selection, and see if it succeeds.
> 
> 
> As a side note, you may want to consider using the
> 'subprocess' module
> instead of manually constructing command strings
> through string
> concatenation: doing it by string concatenation is a
> bug-prone process.
> 'subprocess' is less bug-prone, and you can find out
> more here:
> 
>
> http://www.python.org/doc/lib/module-subprocess.html
> 
> 
> Good luck!
> 
> 




___ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mamelauncher

2005-09-10 Thread Max Russell
I was using 2.3 but upgraded to 2.4 last night because
I had read about the subprocess module (then Danny
also brought tat to my attention.)

The wierd spacing is just Yahoo, sorry!

I'm probably going to try the same project in WX and
then QT, just to get a flavour.

thanks
Max
--- Alan G <[EMAIL PROTECTED]> wrote:

> > I've been working on this for ages and am having
> real
> > problems with getting the wiring for a selected
> game
> > to launch when I click OK.
> 
> So what problems are you having? Do you get an error
> trace?
> A superficial glance tells me only that
> 1) You might find using Tix will simplify your
> code(scrollable 
> listboxes etc)
> 2) Your mailer seems to be adding extra lines, ie I
> assume the code 
> isn't
>really double spaced? :-)
> 
> So whats the specific problem?
> Oh yes - and what version of Python?
> 
> Alan G.
> 
> > I haven't added my error handling yet.
> >
> > Can anyone help?
> >
> > I've tried using spawn, system etc etc to no
> avail.
> >
> > #Mame Launcher
> >
> > #GUI launcher for MAME games
> >
> > #First 'hack' 15th June 2005
> >
> > #Hacking again 19th August
> >
> >
> >
> > import sys, os, subprocess
> >
> >
> >
> > from Tkinter import *
> >
> >
> >
> > class Mamelaunch(Frame):
> >
> >""" GUI application to display MAME games in
> >
> >a list, then launch them. """
> >
> >def __init__(self, master):
> >
> >""" Initialize the frame. """
> >
> >Frame.__init__(self, master)
> >
> >self.grid()
> >
> >self.create_widgets()
> >
> >self.listgames()
> >
> >
> >
> >def create_widgets(self):
> >
> >""" Create button, text, and entry widgets.
> > """
> >
> ># create instruction label
> >
> >self.inst_lbl = Label(self, text = "Please
> > select a game")
> >
> >self.inst_lbl.grid(row = 0, column = 0,
> > columnspan = 2, sticky = W)
> >
> >
> >
> ># create label for password
> >
> >self.pw_lbl = Label(self, text = "Click OK
> > when ready ")
> >
> >self.pw_lbl.grid(row = 12, column = 0,
> sticky
> > = W)
> >
> >
> >
> >#create the scrollbar for the listbox
> >
> >self.yScroll = Scrollbar ( self,
> > orient=VERTICAL )
> >
> >self.yScroll.grid ( row=1, column=1,
> > sticky=N+S )
> >
> >
> >
> ># create listbox to list games
> >
> >self.lstbx =Listbox(self, height = 20,
> > yscrollcommand=self.yScroll.set, borderwidth = 5,
> >
> >relief = "sunken",
> > highlightcolor = "blue",
> selectbackground="orange",
> >
> >selectmode="single")
> >
> >self.lstbx.grid(row = 1, column =
> > 0,sticky=N+S+W)
> >
> >#lock the vertical scroll to the listbox.
> >
> >self.yScroll["command"] = self.lstbx.yview
> >
> >
> >
> ># create ok button
> >
> >self.submit_bttn = Button(self, text =
> "OK")
> >
> >self.submit_bttn.grid(row = 12, column = 1,
> > sticky = S+W)
> >
> >self.submit_bttn.bind("",
> > self.launchmame)
> >
> >
> >
> ># create quit button
> >
> >self.submit_bttn = Button(self, text =
> "Quit",
> > command = self.quit)
> >
> >self.submit_bttn.grid(row = 12, column = 2,
> > sticky = S+W)
> >
> >
> >
> >#Try reading list in prior to creating relevant
> > widgets
> >
> >def listgames(self):
> >
> >"""reads list and populates listbox"""
> >
> >try:
> >
> >mamefile = open('C:\\mamelist.txt',
> > 'r').readlines()
> >
> >except EnvironmentError:
> >
> >print "Please check file is in
> directory"
> >
> >else:
> >
> >#split list, populate listbox
> >
> >for game in mamefile:
> >
> >game = game.rstrip()
> >
> >self.lstbx.insert(END, game)
> >
> >
> >
> >def launchmame(self, event):
> >
> >"""Mechanism to launch MAME game"""
> >
> >selection = self.lstbx.curselection()
> >
> >print selection
> >
> >os.system("C:\\mame096b\\mame.exe"+""+
> > selection)
> >
> >
> >
> > #try:
> >
> > #os.system(echo "game")
> >
> > #except:
> >
> > #SystemError(), "Command not found"
> >
> >
> >
> > # main
> >
> > root = Tk()
> >
> > root.title("MAME Launcher")
> >
> > root.geometry("220x330")
> >
> >
> >
> > app = Mamelaunch(root)
> >
> >
> >
> >
> >
> > root.mainloop()
> >
> >
> >
> >
> >
> >
>
___
> > To help you stay safe and secure online, we've
> developed the all new 
> > Yahoo! Security Centre.
> http://uk.security.yahoo.com
> >
> > 
> 
> 




___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mamelauncher

2005-09-09 Thread Max Russell
Hi:

I've been working on this for ages and am having real
problems with getting the wiring for a selected game
to launch when I click OK.

I haven't added my error handling yet.

Can anyone help?

I've tried using spawn, system etc etc to no avail.

#Mame Launcher

#GUI launcher for MAME games

#First 'hack' 15th June 2005

#Hacking again 19th August



import sys, os, subprocess



from Tkinter import *



class Mamelaunch(Frame):

""" GUI application to display MAME games in 

a list, then launch them. """ 

def __init__(self, master):

""" Initialize the frame. """

Frame.__init__(self, master)

self.grid()

self.create_widgets()

self.listgames()



def create_widgets(self):

""" Create button, text, and entry widgets.
"""

# create instruction label

self.inst_lbl = Label(self, text = "Please
select a game")

self.inst_lbl.grid(row = 0, column = 0,
columnspan = 2, sticky = W)



# create label for password  

self.pw_lbl = Label(self, text = "Click OK
when ready ")

self.pw_lbl.grid(row = 12, column = 0, sticky
= W)



#create the scrollbar for the listbox

self.yScroll = Scrollbar ( self,
orient=VERTICAL )

self.yScroll.grid ( row=1, column=1,
sticky=N+S )



# create listbox to list games

self.lstbx =Listbox(self, height = 20,
yscrollcommand=self.yScroll.set, borderwidth = 5,

relief = "sunken",
highlightcolor = "blue", selectbackground="orange",

selectmode="single")

self.lstbx.grid(row = 1, column =
0,sticky=N+S+W)

#lock the vertical scroll to the listbox.

self.yScroll["command"] = self.lstbx.yview



# create ok button

self.submit_bttn = Button(self, text = "OK")

self.submit_bttn.grid(row = 12, column = 1,
sticky = S+W)

self.submit_bttn.bind("",
self.launchmame)



# create quit button

self.submit_bttn = Button(self, text = "Quit",
command = self.quit)

self.submit_bttn.grid(row = 12, column = 2,
sticky = S+W)



#Try reading list in prior to creating relevant
widgets

def listgames(self):

"""reads list and populates listbox"""

try:

mamefile = open('C:\\mamelist.txt',
'r').readlines()

except EnvironmentError:

print "Please check file is in directory"

else:

#split list, populate listbox

for game in mamefile:

game = game.rstrip()

self.lstbx.insert(END, game)



def launchmame(self, event):

"""Mechanism to launch MAME game"""

selection = self.lstbx.curselection()

print selection

os.system("C:\\mame096b\\mame.exe"+""+
selection)



#try:

#os.system(echo "game")

#except:

#SystemError(), "Command not found"



# main

root = Tk()

root.title("MAME Launcher")

root.geometry("220x330")



app = Mamelaunch(root)





root.mainloop()





___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance difference, ``in'' vs ``has_key()''

2005-07-17 Thread Max Noel


On Jul 17, 2005, at 20:18, Bill Campbell wrote:


Is there any significant performance difference between the
tests, ``key in dictionary'' and ``dictionary.has_key(key)''?
I would prefer using the ``key in'' because it's a bit easier to
type, and can also be used with lists in addition to dictionaries.


While we're on that topic, is there a particular reason why  
'in', in a dict context, searches the keys instead of doing the  
logical thing and searching the values?


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"







___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] populating a listbox from a list

2005-07-15 Thread Max Russell
Hello-

I have a list in this format:

puckman   puckmana  puckmanf  puckmanh  pacman   
pacmanf   puckmod   pacmod  
newpuc2   newpuc2b  newpuckx  pacheart  hangly   
hangly2   hangly3   piranhah
crush crush2crush3maketrax  maketrxb 
korosuke  mbrushpaintrlr
pacplus   joymanctrpllrp  eyes  eyes2
mrtnt gorkans   eggor   
jumpshot  jumpshtp  shootbul  piranha   piranhao 
nmousenmouseb   mspacman
mspacmnf  mspacmat  woodpek   woodpeka  mspacmab 
pacgalmspacpls  ponpoko 
ponpokov  lizwizalibaba   dremshpr  vanvan   
vanvank   vanvanb   bwcasino

and I want to use it to populate a TK listbox:

 def create_widgets(self):
""" Create button, text, and entry widgets.
"""
# create instruction label
self.inst_lbl = Label(self, text = "Please
select a game")
self.inst_lbl.grid(row = 0, column = 0,
columnspan = 2, sticky = W)

# create label for password  
self.pw_lbl = Label(self, text = "Click OK
when ready ")
self.pw_lbl.grid(row = 12, column = 0, sticky
= W)

#create the scrollbar for the listbox
self.yScroll = Scrollbar ( self,
orient=VERTICAL )
self.yScroll.grid ( row=1, column=1,
sticky=N+S )

# create listbox to list games
self.lstbx =Listbox(self, height = 20,
yscrollcommand=self.yScroll.set
highlightcolor="yellow")
self.lstbx.grid(row = 1, column = 0,sticky=W)
#lock the vertical scroll to the listbox.
self.yScroll["command"] = self.listbox.yview

# create ok button
self.submit_bttn = Button(self, text = "OK",
command = self.launchmame)
self.submit_bttn.grid(row = 12, column = 1,
sticky = W)

# create quit button
self.submit_bttn = Button(self, text = "Quit",
command = self.quit)
self.submit_bttn.grid(row = 12, column = 2,
sticky = W)

I'm really not sure how to populate the list though- I
can work with lists just as text, but what do I need
to do to read a list into a listbox.

Should I preformat the list I read from to be one
entry per line?

I don't know if I want to pickle my data as i need to
be able to delete defunct list entries from my little
GUI application.

thanks
Max





___ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions on file.read

2005-07-14 Thread Max Noel


On Jul 14, 2005, at 12:26, Negroup - wrote:


"To read a file's contents, call f.read(size), which reads some
quantity of data and returns it as a string. size is an optional
numeric argument. When size is omitted or negative, the entire
contents of the file will be read and returned; it's your problem if
the file is twice as large as your machine's memory."

What does exactly mean that it's my problem (crash? an exception will
be raised? fire and flames? xyz?). How can my recognize a "too big
file" before read it?


Python will try to read the entire file in memory. Now if the  
file is twice as large as your computer's memory, it will run out of  
it, and then switch to swap space (virtual memory) to fit the rest.
You know how when you're running a resource-intensive game,  
sometimes the action freezes and you hear your hard drive thrashing  
like crazy? Same thing here. Things will slow down to a crawl. If the  
machine is a server, it's obviously a Bad Thing -- however, the box  
shouldn't crash.
Things really get ugly when you run out of swap space. Most OS's  
set the swap file to somewhere between 1 and 2 times your actual RAM  
-- that is, if you have 256 megs of RAM, you can assume that anything  
that requires up to 640 megs will work (albeit slowly).
Now if you manage to fill up both the physical RAM and the swap  
space, there won't be any more space to finish reading the file. If  
that happens, chances are your machine will crash. If it doesn't,  
Python will raise a MemoryError.


In any case, this is something you *don't* want to happen. In  
the big hierarchy of Bad Things, there is only one thing worse than a  
MemoryError:


>>> import sys
>>> sys.is_computer_on_fire()
True


In any cas, you should try to avoid using file.read without a  
size parameter. If you're processing text files, reading them one  
line at a time would be a good start (for line in open 
('filename.txt'): is an instance of Best Thing Ever).



-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"







___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing Data Records in XML File

2005-07-12 Thread Max Noel


On Jul 12, 2005, at 18:44, Gooch, John wrote:

I have a Python script that stores the results of the processing  
that it

does in a
database, but it has to have an alternate way of storing its data in a
database-friendly way (XML)in case the database is not available  
( connected

down, data store full, etc. ).


Any recommendations on a way to do this? i.e. what modules what  
methods?


For all your XML processing needs, you need ElementTree (http:// 
effbot.org/).


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"







___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing Arguments

2005-07-09 Thread Max Noel


On Jul 9, 2005, at 11:17, Don Parris wrote:


get_Name(prt_Name)
# Calling get_Name with prt_Name as the argument produces this:

C:\Python24>python scripts\learning.py
f


At least it found the function.  That's little shy of a miracle for
me. :)  However, I would like to see 'foo' printed out, since it is
the result of the function.  How can I correct this?


You have to call the function:
get_Name(prt_Name())

prt_Name is the function itself. prt_Name() (note the parens)  
calls (executes) the function and allows you to use its return value.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"







___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Initialising attributes with random values

2005-07-05 Thread Max Russell
Hello there;

If I have a class and want to initalise it, with
random values assigned to the attributes, what is the
best way of doing this?

For example:

def __init__(self, name, size = 0, strength = 0):
self.name = name
self.size = size
self.strength = strength

starts with values of 0. But how can I neatly say,
start with a random value from (for example) 1 - 5?

thanks
Max



___ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT self-implementation?

2005-07-01 Thread Max Noel


On Jul 2, 2005, at 01:43, Brian van den Broek wrote:


This sounds, to the untutored, rather like magic. (It reminds me of a
line from the German mathematician and philosopher, Gottlob Frege,
who, in a book on the foundations of arithmetic, characterized an
opposing position as akin to "trying to pull yourself out of the swamp
by your own top-knot" -- which, I can only assume, is even funnier in
the original 19th c. German ;-) Naively, one thinks that to write
anything in C, you'd have to *have* C to write in, etc.


Actually, there's not much to it that's magic. The idea is that  
before being able to self-implement a language, you implement it in  
another language first (usually, but not always, ASM). Before C was  
written in C, it was written in assembly language.

To get a C compiler that's itself written in C, here's what you do:

1. Obtain a C compiler. Any C compiler, let's call it "fooCC". It  
doesn't matter as long as it compiles correctly.
2. Your C compiler will be called "barCC". Write its source code in  
C. Not hard to do as C code is just ASCII text.
3. Compile barCC's source code with fooCC. The resulting compiler  
(let's call it "bazCC") is not barCC yet. It produces the same output  
as barCC, but the process is not complete as it was itself produced  
using a compiler that wasn't written in C.
4. Compile barCC's source code with bazCC. Since bazCC and barCC  
produce the same output, what you get is equivalent to barCC compiled  
with barCC itself: it *is* barCC. You have your compiler.
5. (optional) Make sure the previous statement is true: recompile  
barCC with barCC, and assert that the output is identical to the  
compiler produced in 4.


The whole process is called "bootstrappping" (from the  
Adventures of Baron Munchausen, as you mentioned), and exists for all  
compiled languages (including assembly). In fact, every language  
except microcode was at some point either bootstrapped or cross- 
compiled.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"







___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing what you've already printed

2005-06-22 Thread Max Noel


On Jun 23, 2005, at 01:04, Alan G wrote:



Curses comes as standard on linux...



They also do on Windows. Just listen to any user when the bloody  
thing crashes. (sorry, couldn't resist :p )



More seriously, I seem to recall that on the contrary, the  
Windows Python distribution does not include the curses module (you  
have to use msvcrt[?] instead). I wonder why, because I'm pretty sure  
I saw (C) curses-based applications running on Windows (NetHack is  
one, AFAIK).


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"








___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max(len(item)) for cols

2005-06-17 Thread Max Noel

On Jun 17, 2005, at 11:58, János Juhász wrote:

>
> Dear Guys,
>
> I have a 2D array:
>
>>>> [['1', '2 ', '3'], ['longer ', 'longer', 'sort']]
>>>>
>
>
> How can I  get what is the max(len(item)) for the columns ?
> I would like to get a list with the max_col_width values.
>
> I hope that, it can wrote with some nice list comprehension, but I  
> can't do
> that :(


 >>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1]]
 >>> max(len(item) for item in a)
4

 If you're running Python 2.3 or lower, add brackets in the last  
line:
 >>> max([len(item) for item in a])
4


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] can't see emacs timer in action

2005-06-14 Thread Max Noel

On Jun 14, 2005, at 23:17, Pujo Aji wrote:

> I just use Ctrl+C Ctrl+C to run the code.
> The code wait for 3 second and show all i all together.
>
> I can't feel every second pass.
>
> pujo

 Try running your script from a terminal (outside of emacs, that  
is).

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] can't see emacs timer in action

2005-06-14 Thread Max Noel

On Jun 14, 2005, at 22:56, Pujo Aji wrote:

> Hello,
>
> I tried this code in emacs.
> for i in range(3):
>   time.sleep(1)
>   print i
>
> It shows the result but total result not second per second.
>
> Any one experiance this problem
>
> pujo

 Works for me... How do you run it? Do you use a separate  
terminal window, or do you use some kind of "run with Python" command  
in emacs? (not sure how it's done, I'm a vim user myself)
 Did you make sure you import time before that code is run?

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] "Print" behaviour inside a loop?

2005-06-11 Thread Max Noel

On Jun 12, 2005, at 00:42, Simon Gerber wrote:

> Any hints? I looked up the python reference manual, but couldn't find
> any way to force print statements to draw. Should I be looking into
> threads, perhaps?

 I/O in Python is buffered -- that is, it uses RAM whenever  
possible to delay the actual reading/writing operations, which in  
turn speeds them up. For example, when you read a character from a  
file, a larger part of the file is stored in a RAM buffer so as to  
speed up subsequent calls.
 In the same way, whenever you write to stdout (or to a file),  
everything is stored in a buffer until a newline is reached or the  
buffer is manually flushed. The latter is what you're looking for,  
it's done by calling the file object's (in your case, stdout --  
remember, on UNIX everything is a file) flush method.
 Here's a small example:

#!/usr/bin/env python
import time, sys

for i in xrange(20):
 sys.stdout.write(".")
 sys.stdout.flush()
 time.sleep(0.2)


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] Calling a function

2005-06-09 Thread Max Noel

On Jun 9, 2005, at 07:45, Kevin Reeder wrote:

> I'm having trouble with this code which is meant to run a time
> comparison between two similar functions. The first module is
> makezeros.py
>
> def lots_of_appends():
> zeros = []
> for i in range(1):
> zeros.append(0)
>
> def one_multiply():
> zeros = [0] * 1

 Note that your functions don't do the same thing. The first one  
builds the list properly, but the second builds a list out of  
references to the same object -- that is, the 1 zeros in your  
resulting second list are actually the same object.
 As long as you're working with immutable types (numbers,  
strings) you won't notice there's a problem, but consider the following:

 >>> a = [[0]] * 10
 >>> a[0].append(1)
 >>> a
[[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0,  
1], [0, 1]]

[0] is a list -- therefore, a mutable object: you can apply  
modifications to it. So, the list is actually a list of ten  
references to the same object -- [0]. When you run one of its methods  
that modifies it, since all references point to it, all members of  
the list seem to be modified as well -- but they're actually one  
single object that's present 10 times in the list.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] repr()

2005-06-07 Thread Max Noel

On Jun 7, 2005, at 20:42, Bernard Lebel wrote:

> repr( myFunc )
>
> Wich returns
>
> ''
>
>
> Okay then I run
>
> s = repr( myFunc() )
> print s
>
> Wich returns
>
> 'None'

 That's perfectly normal. Your last assignment calls the  
function, then assigns to s the representation of the function's  
return value. A function that doesn't have a return statement returns  
None, and repr(None) == 'None'. Which is what you get.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] Detecting my own IP address?

2005-06-06 Thread Max Noel

On Jun 6, 2005, at 05:27, Bill Campbell wrote:

> I don't do Windows so can't say what it does (knowing Microsoft, it  
> may
> vary between Windows versions, patch levels, and the phase of the  
> moon :-).
>
> Bill

 Well, Windows doesn't even do ifconfig. The (more-or-less)  
equivalent command is ipconfig, except that it has no generic names  
for network interfaces. What that means, is that instead of eth0 (or  
en0, or whatever), it uses the full name of your NIC -- which  
effectively means that the output differs from one machine to  
another. Good luck with this one :D

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] quick PIL question

2005-06-02 Thread Max Noel

On Jun 2, 2005, at 23:39, Terry Carroll wrote:

> The palette mode ("P") uses a colour palette to define the actual
> colour for each pixel.
>
>
>
> Not sure what that means, exactly, but it looks like im.palette  
> will get
> the palette of a a P-mode image, and im.putpalette will change it.
>
> I'm not sure how to interpret the palette once you have it,  
> though.  The
> description of the ImagePalette class is not too helpful.

 Here's what this means. Computers nowadays use 24-bit display  
modes (8 bits for each of the components R, G and B -- 32-bit display  
is the same thing with an extra 8 bits of alpha/transparency). That  
is, 16.7 million different possible colors.
 GIF images, on the other hand, are 256-color (8-bit) images.  
However, these 256 colors are not fixed: they can be any of the  
regular 16.7 million.
 This is where the palette comes into play. Each 256-color image  
has a palette, which is basically an array of length 256, where each  
element is a (24-bit RGB) color. The color data for each pixel in the  
image is actually an index in this array.

 Makes sense?

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


[Tutor] Fwd: xml

2005-05-24 Thread Max Noel
(meh, forgot to click "reply-all" again)

Begin forwarded message:

> From: Max Noel <[EMAIL PROTECTED]>
> Date: May 24, 2005 23:01:39 BDT
> To: "D. Hartley" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] xml
>
>
>
> On May 24, 2005, at 22:59, D. Hartley wrote:
>
>
>> anyone have a pointer to a *SIMPLE* intro to xml as used in python? I
>> looked in the library and there are about 11 xml-related modules.
>>
>
> The most elegant way to use XML in Python is to use the  
> elementtree module (http://effbot.org/zone/element-index.htm). It's  
> pure goodness.
>
> -- Max
> maxnoel_fr at yahoo dot fr -- ICQ #85274019
> "Look at you hacker... A pathetic creature of meat and bone,  
> panting and sweating as you run through my corridors... How can you  
> challenge a perfect, immortal machine?"
>
>

-- 
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] Python won't play wav file

2005-05-24 Thread Max Noel

On May 24, 2005, at 02:49, Joseph Quigley wrote:

> ... to play a .wav music file. I tried w.play() but got an error that
> module has no attribute 'play'.
> What do I use to get it to play?
> Thanks,

 The wave module is meant to read, write and manipulate  
(transform, filter, whatever) WAV files, not to play them.
 Playing a sound is a highly OS-specific function; PyGame is a  
cross-platform library that enables this, among other things.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] Filtering Spreadsheet Data

2005-05-24 Thread Max Noel

On May 24, 2005, at 14:22, Mike Hansen wrote:

> Excel has some nice database-like queries itself. Take a look at  
> Advanced Filter
> in Help. You can essentially query a worksheet and even send the  
> results to a
> different worksheet. I'd imagine that once you got the query  
> working, you could
> automate it using VBA or Python.
>
> Mike

 If you want to do it in Python, the easiest way is to export the  
spreadsheet as CSV in Excel, then use the csv module to do your  
processing. If needed, convert back to XLS afterward.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] looking for a pattern in a lot of files

2005-05-22 Thread Max Noel

On May 22, 2005, at 21:07, Jonas Melian wrote:

> for line in fileinput.input(glob.glob(os.path.join
> (dir_locales, "*_[A-Z][A-Z]"))):
> if re.search("locale for", line):
> print line

 If you're only looking for the occurrence of a string and not a  
regex pattern, you don't have to use regular expressions:


if "locale for" in line:
 print line


 Works just as well, and is faster.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] using -i flag with '''if __name__ == "__main__":'''

2005-05-19 Thread Max Noel

On May 19, 2005, at 23:05, Terry Carroll wrote:

> Thanks to you both.  I think I may need to step up my "development
> environment" beyond emacs and a command line.

 Actually, if you're having problems with debugging your problem,  
what you should step up is your approach to debugging/testing.
 Unit tests (the unittest module, which is itself derived from  
the Java JUnit framework) are an instance of BestThingEver,  
especially if you're using the OO paradigm. They basically allow you  
to prove the correctness of each part of your program.
 And trust me, the time you take to write them is by far lower  
than the time they save you tracking and correcting bugs if you don't.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] kernel serie

2005-05-19 Thread Max Noel

On May 19, 2005, at 23:28, Jonas Melian wrote:

> I want get the kernel serie, so 2.x only (2.6 or 2.4)
>
> info_kernel = platform.release() # get the kernel version
> info_kernel = '.'.join(info_kernel.split('.',2)[:2])
>
> is there any way of get it in one line only?

 Based on your code, that'd be:

info_kernel = '.'.join(platform.release().split('.',2))

 The [:2] is unnecessary, as you're limiting the number of splits  
to 2, so the resulting list from split() can't have more than 3  
elements.

 Also, note that this code will likely cause the program to crash  
on any system that isn't Linux. On my box (OS X 10.4.1), for example,  
sys.platform returns 'darwin'.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


  1   2   3   >