[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] .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 rus...@winder.org.ukwrote:

 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


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 ajarnco...@gmail.com 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] 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 mrsann...@yahoo.com 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] 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 nidia...@hotmail.comwrote:


 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


[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] sifting through a long program

2011-11-10 Thread Max S.
Alt+G, or EditGo To Line.

On Thu, Nov 10, 2011 at 1:58 PM, Nathaniel Trujillo
hothottr...@gmail.comwrote:

 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


[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] 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
li...@solderintheveins.co.ukwrote:

 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/tutorhttp://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] Tutor Digest, Vol 92, Issue 77

2011-10-16 Thread Max S.
On Sun, Oct 16, 2011 at 3:44 PM, tutor-requ...@python.org wrote:

 Send Tutor mailing list submissions to
tutor@python.org

 To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
 or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

 You can reach the person managing the list at
tutor-ow...@python.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Tutor digest...


 Today's Topics:

   1. Re: 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: j7f2ra$7dp$1...@dough.gmane.org
 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 fo...@yahoo.com
 To: Hugo Arts hugo.yo...@gmail.com
 Cc: Python Mailing List tutor@python.org
 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 hugo.yo...@gmail.com
 To: Albert-Jan Roskam fo...@yahoo.com
 Cc: Python Mailing List tutor@python.org
 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 fo...@yahoo.com
 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 your actual script through it. Or you could set the
 environment variable 

[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


[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] Generic For Loop

2011-10-12 Thread Max S.
Thanks!

On Wed, Oct 12, 2011 at 8:56 PM, bob gailer bgai...@gmail.com 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