Re: [Tutor] learn python to build payment processor

2018-07-12 Thread Leam Hall

On 07/11/2018 05:41 PM, Anil Duggirala wrote:

You don;t tell us your experience level.


Im not a complete newbie, I understand basic programming.



Anil, if you are doing this for a class project, or as a way to learn 
Python, then I applaud you! It will take time and be difficult but you 
will learn a lot.


However, if you are actually thinking about using this to process 
payments, please stop. Don't do that. Not because you're not smart 
enough but because none of us is smart enough. Companies have entire 
teams writing this sort of code and other teams reviewing the code. Even 
then, there are significant security risks.


Financial transaction code that has flaws can ruin people's lives. I've 
already had my card misused this year, it took me a week of effort to 
recover. That was much less than it would have been if we didn't have 
stringent controls in place.


Please code responsibly.

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


Re: [Tutor] C++ or Python?

2018-07-03 Thread Leam Hall
Howard is right. You will produce actual code doing actual stuff much 
faster with Python than with C++.


There are ways to resolve performance bottlenecks but most people don't 
actually hit those sorts of issues.


Leam

On 07/03/2018 01:06 PM, Howard B wrote:

  Greetings --

Faster to do what?  Develop faster?  Run faster?  Debug faster?

In my experience, making the development and eventual debugging of programs
as easy and quick as possible is very important.  My experience and advice
has been to design a clear algorithm, then program it in as clear and
straightforward a manner as possible in a language that has good support.
Test the program for correctness.  After it works as hoped, test it for
speed.  Only then, and only if necessary, analyze, profile, and optimize
the code for speed.  Keep in mind that modifying the program to increase
speed will make it less clear and will probably make it more difficult to
maintain, even by its original programmer.

That said, Python is much easier to code and to debug than C++ (I have
considerable experience with both).  When necessary, identify the portions
of the program that are the bottleneck and optimize them in a step-by-step
manner -- most constricting bottleneck first, then reevaluate, etc.  That
optimization may be as simple as replacing Python routines with Cython
routines.
http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html

Best,  Howard (50 years in computing, including commercial programming
and university professor)


On Tue, Jul 3, 2018 at 9:26 AM Bellamy Baron 
wrote:


Hi,

I have heard C++ is faster than python and I have a few questions
1.Is there a way to make python run just as fast
2.can I get in a serious game making team like 343 by using python
3. if C++ is better where can I get good 3d model libraries and libraries
that make coding in C++ faster
4. Is there a way to transfer python files to C++

Thanks

--


Bellamy
iWYZE
https://www.iwyze.co.za/products/car-insurance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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


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


Re: [Tutor] Async TCP Server

2018-04-25 Thread Leam Hall

On 04/25/2018 05:14 PM, Simon Connah wrote:

Hi,

I've come up with an idea for a new protocol I want to implement in
Python using 3.6 (or maybe 3.7 when that comes out), but I'm somewhat
confused about how to do it in an async way.

The way I understand it is that you have a loop that waits for an
incoming request and then calls a function/method asynchronously which
handles the incoming request. While that is happening the main event
loop is still listening for incoming connections.

Is that roughly correct?

The idea is to have a chat application that can at least handle a few
hundred clients if not more in the future. I'm planning on using
Python because I am pretty up-to-date with it, but I've never written
a network server before.

Also another quick question. Does Python support async database
operations? I'm thinking of the psycopg2-binary database driver. That
way I can offload the storage in the database while still handling
incoming connections.

If I have misunderstood anything, any clarification would be much appreciated.

Simon.


How does your idea differ from Twisted?

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


Re: [Tutor] XML Programs

2018-04-16 Thread leam hall
Yeah, understood.

Okay, knowing that others are smarter about python, and ElementTree,
here's some code I was using to parse XML. Took a while to recover
from.  :)

Leam

#

import xml.etree.ElementTree as ET
import os
import argparse
import fnmatch

def show_info(file, element):
  action  = ""
  net_proto   = ""
  trans_proto = ""
  r_port  = ""
  l_port  = ""
  direction   = ""
  name= ""
  has_info= False
  f_name  = ""

  id= element.attrib['name']
  f_name= os.path.splitext(file)[0]

  for setting in element.iter('Setting'):
if setting.attrib['name']  == 'Action':
  action= setting.attrib['value']
  has_info  = True
elif setting.attrib['name'] == '+NetworkProtocol#0':
  net_proto = setting.attrib['value']
  has_info  = True
elif setting.attrib['name'] == '+TransportProtocol#0':
  trans_proto = setting.attrib['value']
  has_info= True
elif setting.attrib['name'] == '+RemotePort#0':
  r_port= setting.attrib['value']
  has_info  = True
elif setting.attrib['name'] == '+LocalPort#0':
  l_port= setting.attrib['value']
  has_info  = True
elif setting.attrib['name'] == 'Direction':
  direction = setting.attrib['value']
  has_info  = True
elif setting.attrib['name'] == 'Name':
  name  = setting.attrib['value']
  has_info  = True

  if has_info:
outfile.write("%s ; %s ; %s ; %s ; %s ; %s ; %s ; %s ; %s\n" %
(f_name, id, name, action, net_proto, trans_proto, l_port, r_port, direction))



## Main
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--outfile", default = "new_out.csv",
help="File to write to.")
parser.add_argument("-d", "--dir", default = ".", help="Directory of
the XML files.")
args = parser.parse_args()

indir   = args.dir
outfile = open(args.outfile, 'w')
outfile.write("File ;Rule ID ;Name ;Action ; Network Protocol;
Transport Protocol; Local Port; Remote Port; Direction\n")

for file in os.listdir(indir):
  if fnmatch.fnmatch(file, '*.xml'):
full_file = indir + "\\" + file
tree   = ET.parse(full_file)
root   = tree.getroot()
for element in root.iter('PolicySettings'):
  show_info(file, element)

outfile.close()



On Mon, Apr 16, 2018 at 9:07 AM, Glen  wrote:
> I understand, I'd love to use something else but the save game files are in
> XML so I have no choice :'(
>
> On 16 April 2018 at 13:54, leam hall  wrote:
>>
>> On Mon, Apr 16, 2018 at 7:10 AM, Glen  wrote:
>> > Hey guys,
>> >
>> > I'm writing a save-game editor for a game I play (just a project to
>> > learn).
>> > But I am struggling on how to structure the code, how to store the xml
>> > data
>> > in data structure etc,
>> >
>> > Can anyone recommend some source I can review that reads and writes data
>> > from an xml file.
>>
>> A friend's comment was "life is too short for XML". I like that. Have
>> you considered JSON? Taking it a step further, MongoDB (JSON) or
>> SQLite (SQL)? Both are pretty common and standard.
>>
>> While Python has its own stuff, like Pickle, that means you can only
>> use Python. Using something like JSON or SQL means others can use the
>> data and you get a chace to develop in a shared environment.  :)
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML Programs

2018-04-16 Thread leam hall
On Mon, Apr 16, 2018 at 7:10 AM, Glen  wrote:
> Hey guys,
>
> I'm writing a save-game editor for a game I play (just a project to learn).
> But I am struggling on how to structure the code, how to store the xml data
> in data structure etc,
>
> Can anyone recommend some source I can review that reads and writes data
> from an xml file.

A friend's comment was "life is too short for XML". I like that. Have
you considered JSON? Taking it a step further, MongoDB (JSON) or
SQLite (SQL)? Both are pretty common and standard.

While Python has its own stuff, like Pickle, that means you can only
use Python. Using something like JSON or SQL means others can use the
data and you get a chace to develop in a shared environment.  :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonic

2018-04-02 Thread leam hall
On Mon, Apr 2, 2018 at 9:01 AM, David Rock  wrote:

> It’s just as (if not more) pythonic to use the standard libraries. It’s very 
> common in a professional environment to not have access to outside (i.e., 
> internet) resources.  I wouldn’t venture into Pypi unless there’s something 
> you can’t do well with what’s already provided by default.

+1.

Use standard libraries; most places I've worked didn't allow a lot of
non-standard library code at all. If something is in the standard
library you have some level of assurance that the maintenance is
moderated and monitored.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Need help with reading and cleaning CSV files for a class

2018-01-28 Thread leam hall
On Sun, Jan 28, 2018 at 8:36 AM, Geoff Hancock  wrote:
> Good day-
> I'm in a difficult situation.
> I have been asked to help teach students how to clean up a CSV file in
> Python.
> The job has fallen to me because the teacher of the course is out on
> emergency leave and I just found out.
> Tomorrow I have to show students how to get a CSV file and write code to
> clean and parse it.
>
> I understand the process--BUT I don't know how to do it!
> What I'm looking for is a simple
> Step 1
> Step 2
> Step 3 etc
> I'm running the latest version of Python and am running on Windows
> Can anyone assist?
>
> Much appreciate the time
> JGH


Geoff, I'm not that great a coder but here's where I would start.
Assume a file name "gang_draft.csv" that is colon delimited since I'm
working on stuff for an RPG session.  :)



file = open('gang_draft.csv', 'r')
for line in file:
  line = line.strip()
  line_array = line.split(':')
  print(line_array[1])



Where I have print you can do whatever cleanup you like. Then either
print specific columns or join them back into a string.

Hope that helps start you in the right direction. Others here will
likely come up with better solutions.

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


Re: [Tutor] IDLE

2017-12-30 Thread Leam Hall

On 12/30/2017 04:07 AM, Alan Gauld via Tutor wrote:


Videos are good for getting a feel for things and
understanding concepts but IMHO they are not good
for details. 


This is how I learn coding languages. Watch a video series for a little 
bit and then find a written tutorial to work through. Getting the "big 
picture" quickly helps provide a context and then digging deeply into 
the actual code really helps learning.


And yeah, I'll plug Alan's tutorial. I can't think of any reason not to 
use it.


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


Re: [Tutor] When do you know you're ready to start applying for jobs?

2017-12-12 Thread leam hall
On Tue, Dec 12, 2017 at 2:43 PM, Matthew Ngaha  wrote:

> Can I get a junior programming job without a CS degree?
> When do you know you're ready to start applying for jobs? How can a
> self learner ever know?
> should I have applied for some jobs back in 2015 when I was still studying?
> What are your opinions on my situation? Is learning Python all over
> again worth it without a CS degree? would I be wasting my time?
>


Most of the bugs in current commercial software packages were written by CS
grads. Keep that in mind.

The real question is, "do you enjoy coding so much you stay a newbie?"
There are always things to learn. Do the Tutor stuff. Do CodeWarrior. If
you enjoy it then look at job listsing and play with the stuff they are
asking for. Continue to take classes.  Work through a book of advanced
topics. Help with open source projects. Answer questions for newbies when
you can.

If that's the life you want to lead then jump in. It will be a second job
that doesn't pay for a while, but if you keep it up you'll find the right
spot.

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


Re: [Tutor] Standard module sqlite3 or APSW?

2017-09-09 Thread leam hall
On Sat, Sep 9, 2017 at 8:56 PM, boB Stepp  wrote:

> First, if I have not misinterpreted anything, the subject header is
> perhaps better written as "pysqlite or APSW?"  As far as I can tell
> from reading the documentation at
> https://docs.python.org/3/library/sqlite3.html , the module sqlite3 is
> in actuality using the pysqlite project.
>
> So if all of this is correct, does the documentation at
> https://rogerbinns.github.io/apsw/pysqlite.html#pysqlitediffs give an
> objective assessment of the differences between pysqlite and APSW?
>
> The bottom line results I am getting from that page is:
>
> (1) If my database needs are simple, go with the standard library
> module, sqlite3.
>
> (2) If I wish to use all of the latest, greatest features of SQLite3,
> and I don't care about some of its non-standard SQL implementations,
> then use APSW if SQLite3 meets my database needs and I don't
> anticipate having to upgrade to one of the big database projects.
>
> (3) If I am prototyping a database solution, anticipating
> transitioning to one of the big database projects, then use the
> standard library sqlite3 as it will make it easier to make the
> transition, due to better SQL standardization.
>
> Am I getting the correct understanding of the pros and cons?
>
> A further question.  Is APSW being maintained solely by a single
> person?  That is, is it likely to be around for years to come?
>
> TIA!
>

>From a newbie, my choices are usually guided by "what's in the stdlib?"
Starting there tends to take me pretty far and if I get to the bumpy parts
I know exactly why I might want to change. Staying with the stdlib also
means others can use my code with minimal fuss.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How is database creation normally handled?

2017-09-09 Thread leam hall
On Sat, Sep 9, 2017 at 8:29 PM, boB Stepp  wrote:

> While reading about SQL, SQLite and the Python module sqlite3, it
> appears that I could (1) have a program check for the existence of the
> program's database, and if not found, create it, make the tables,
> etc.; or, (2) create the database separately and include it with the
> program.  What are the pros and cons of each approach?  (1) to me
> looks only helpful if I wish to write a program that might want to
> allow the user to have multiple databases.  But this sounds like a lot
> of extra coding and checking to make it work well.  But if I only wish
> to have a single database, then (2) sounds like the approach to use.
> I would create the database, populate it with the needed empty tables
> with the desired fields, making it ready to use by the program's user.
>
> Not having any experience in the database arena, I'm not even sure I
> know how to properly think about this.
>


I'd write a configure script separate to set things up. It only gets run
when needed and you can change the process if you want to move from SQLite3
to MongoDB or whatever. It also lets the user set up test databases.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3 for Beginners was: (Re: intro book for python)

2017-09-03 Thread Leam Hall

On 09/03/2017 10:06 AM, David Rock wrote:



On Sep 3, 2017, at 08:55, Mats Wichmann  wrote:

On 09/03/2017 04:02 AM, Leam Hall wrote:


Anyone that uses python on Linux has to use Python 2.


Every current distro I know of has a python 3 package, plus lots and
lots of add-ons in python 3 mode.  It's quite easy to use python 3 as a
result... and if that doesn't work you can install your own to your
workspace (rather than as a "system package") just as easily.


While a bit anecdotal, the complaint is valid.  Red Hat does not support Python 
3 in their base installation on RHEL and the only way to get it “officially” 
(i.e., directly from Red hat) is through Software Collections, which is a bit 
cumbersome to use and not available in all cases.  There are a lot of places 
(including where I work) that frown heavily on using packages that aren’t from 
the base repositories from the OS maintainers.

Installing into “your own workspace” isn’t so easy when you are talking about 
2000 servers, either.  In order for me to write code that I know will work 
across all the servers, I have to use python 2 because I know it will be there. 
 I can’t say the same thing about python 3, and that’s not something I’m likely 
to be able to fix within the bounds of company procedures.

So while the original statement is obviously false, the heart of why it was 
said is functionally true.


Sorry; there's a significant gap between what I wrote and what I meant. 
My fault.


If you use the OS system's Python then you're using Python 2. That will 
continue for the next five or more years. I'm in the same boat as David; 
installing Python 3 is a non-starter. That's not the case for a lot of 
folks, but if I'm going to write something there's a high probability 
that Python 3 won't be on the target machine.


While I prefer 2 over 3, if I went in to work and everything was 
magically Python 3 based I wouldn't whine. Much.


Sorry for the miscommunication earlier.

Leam

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


[Tutor] Python 3 for Beginners was: (Re: intro book for python)

2017-09-03 Thread Leam Hall

On 09/03/2017 12:10 AM, Mark Lawrence via Tutor wrote:

On 01/09/17 18:51, Raghunadh wrote:

Hello Derek,

I would start with this book

https://learnpythonthehardway.org

Raghunadh



I cannot recommend anything from the author of LPTHW after he had the 
audacity to write this 
https://learnpythonthehardway.org/book/nopython3.html about Python 3, in 
addition to which there are several vastly superior books and/or 
tutorials anyway.


Kindest regards.

Mark Lawrence.


There are lots of other books on Python, that's true. "Practical 
Programming" (Gries, Campbell, Montojo) is one I use.


Are you going to toss "Learning Python" since Mark points out some of 
python's drift from it's core values?


I appreciate that link. Zed's right. Python 3 isn't used by the OS tools 
on Red Hat, and that's that major Linux vendor in the US. Has SuSE 
converted all OS tools to require Python 3? Ubuntu 18 is supposed to be 
Python 3 only, whenever it gets out.


Anyone that uses python on Linux has to use Python 2. That means Python 
3 is just one more language that requires work to install and maintain. 
I'm not seeing the benefits. How long has Python 3 been out? How many 
others are seeing the benefits of total change? When will people who say 
"you should upgrade" realize it's weeks or months of work with no real 
reason to do so?


Yesterday I was coding and had to work around Python 3 dict.keys() 
returning a "dict_keys" type vs a list. Why did we need another type for 
this? I'm a coding beginner. I can talk a decent game in a few languages 
like python but I'm not experienced enough or smart enough to deal with 
these sorts of problems easily. Returning a new type, without 
significant benefit, makes it harder for people to progress in the 
language.


Some years ago I wanted to play with an IRC bot sort of thing. Someone 
on Freenode #python mentioned Twisted so I got that and started playing. 
Half an hour, maybe forty five minutes later and my little project did 
what I was trying to do. This was before I really knew any python; the 
language was that clean and easy to learn.


I'd prefer Zed be wrong about Python dying. I'm not willing to put any 
money on it though.


Leam


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


[Tutor] Free Python Class on Coursera

2017-06-13 Thread leam hall
Hey everyone,

There's a free pair of Python classes on Coursera. I'm fixing to take the
second one "https://www.coursera.org/learn/program-code"; that starts 26
Jun. If you've been here for a while and learned the basics, now is a good
time to up your skills.

If you are new here the first of the series is available. The next one
starts 3 Jul and they run them a few times a year.

  https://www.coursera.org/learn/learn-to-program


I took the first class some time back and enjoyed it. if anyone wants to
join me on the second class, hop in! The class is free though Coursera
wants to ask you for money anyway.

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


Re: [Tutor] (no subject)

2017-05-10 Thread leam hall
Oh...Spam with Curry!

On Wed, May 10, 2017 at 8:18 PM, Alan Gauld via Tutor  wrote:
> On 11/05/17 01:02, Steven D'Aprano wrote:
>> Looks like spam to me. A link to a mystery URL with no context, by
>> somebody signing their email with a radically different name from the
>> email address used,
>
> And the address is not subscribed to the list so the message
> should have gone to moderation.
>
> I'm trying to find out what happened here...
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] understanding code testing

2017-04-15 Thread leam hall
For python specific I'd look at unittest:
https://docs.python.org/3/library/unittest.html?highlight=test#module-unittest

For testing in general then "Test Driven Development By Example" by Kent
Beck. Examples are in Java but he explains the theory.

I've been on a testing kick lately and am slogging through Binder's
"Testing Object Oriented Systems". It's a great book, well written, but
still a bit over my head. I wasn't a math whiz in school.

Lots of web pages on testing, and probably some on python TDD if you make
sure it's not focusing on Django. Unless you're doing Django, that is.

Leam

On Sat, Apr 15, 2017 at 1:10 PM, Joel Goldstick 
wrote:

> On Sat, Apr 15, 2017 at 10:33 AM, Rafael Knuth 
> wrote:
> > can anyone point me to good learning resources on this subject?
> > (python 3)
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
> This looks like a good book: http://www.obeythetestinggoat.com/
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating .json files

2017-04-13 Thread leam hall
On Thu, Apr 13, 2017 at 12:32 PM, Rafael Knuth 
wrote:

> Is there a way to split these two into separate steps:
> a) creating a .json file
> b) manipulating it (a, r, w ...)
>
> Example:
>
> "import json
> number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
> file_name = "my_numbers.json"
> with open(file_name, "w") as a:
> json.dump(number_list, a)
>
> What if I just wanted to create a .json file and do nothing with it?
>
> import json
> file_name = "my_numbers.json"
>
> The above does not do the job. What am I getting wrong here? Thanks.
>
> If you want to have a file after the program runs you need to "open" it.
And close it. Otherwise you reference a file but leave no trace.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Socket error in class, part the second

2017-03-10 Thread leam hall
y'all,

Thanks for the explanations! Sorry for the delay in responding, it's been a
rough year these past couple weeks.

As noted, the fix was to put the "import socket" above the class
declaration. What confuses me is that in the calling program I'm importing
the class:

  from mysocket import mysocket

In mysocket.py the "import socket" is above the class declaration. This
works. I would have thought it would fail as the import statement only
imports the class, not the entire module. However, I'm wrong. Still
learning.

Also, yes, I re-typed everything which is why the errors crept in. The
machine I have to run python on precludes cut and paste to the machine I
e-mail on. The original code was swiped from Gordan McMillian's tutorial on
Python.org.

https://docs.python.org/2/howto/sockets.html

I'm just trying to make things modular.

Again, thanks!

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


[Tutor] Socket error in class

2017-03-06 Thread leam hall
What am I missing?


class mysocket():
  import socket
  def __init__(self, sock=None);
if sock is None:
  self.sock = socket.socket(socket.socket.AF_NET,
socket.socket.SOCK_STREAM)
else:
  self.sock = sock



Error:
NameError: global name "socket" is not defined.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] looping - beginner question

2017-03-02 Thread leam hall
On Thu, Mar 2, 2017 at 8:42 AM, Rafael Knuth  wrote:

> I wrote a program that is supposed to take orders from customers in a bar.
> If the desired drink is available, the customer will be served. If
> not, he will be informed that the drink is not available. This is what
> I wrote:
>
> bar = ["beer", "coke", "wine"]
>
> customer_order = input("What would you like to drink, dear guest? ")
>
> for drink in bar:
> if customer_order != drink:
> print ("Sorry, we don't serve %s." % customer_order)
> else:
> print ("Sure, your %s will be served in a minute!" %
> customer_order)
>
> What I want the program to do is to "silently" loop through the list
> of drinks and to print the correct answer. Instead, it loops through
> each item on the list like this:
>
> >>>
> == RESTART: C:/Users/Rafael/Documents/01 - BIZ/Python/Python Code/PPC_4.py
> ==
> What would you like to drink, dear guest? coke
> Sorry, we don't serve coke.
> Sure, your coke will be served in a minute!
> Sorry, we don't serve coke.
> >>>
>
> Rafael, don't forget that your input string might have a newline character
that needs to be cleaned off. I think, can't test at the moment. The
simplest test might be:

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


Re: [Tutor] Learning Objectives?

2017-03-01 Thread Leam Hall

On 02/28/17 05:24, M Hashmi wrote:

Coding is an artthat helps you craft beautiful things in digital world.
As beginner it's pretty natural to confuse about which learning curve can
benefit you most in future.



I see computer science as a science that calls upon our creative nature 
to produce excellence. Adding constraints like secure coding and TDD 
push us to even greater artistic expression. Lack of constraints gives 
us the current standard of non-performant and insecure code.


Hence my desire for the basic tools of science and engineering. What do 
I need to know to produce solid code in a team of solid coders.


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


Re: [Tutor] Learning Objectives?

2017-02-28 Thread Leam Hall

On 02/27/17 20:12, Alan Gauld via Tutor wrote:

On 27/02/17 14:57, leam hall wrote:


I'm not aware of such a list, and I'm not sure it's of much value.
Better to just learn what you need and use it. ...



When I was coming up as a Linux guy I took the old SAGE guidelines and
studied each "level" in turn. It was useful for making me a well-rounded
admin and helped me put off some higher end stuff I wasn't really ready
for.


Its an individual choice, so if it works for you don't let
me stop you :-) But I still don't know of any such list.


Understood. However, think about the issue from a newbie perspective.

1. The Python Tutor e-mail list helps with questions when someone can 
frame a question.


2. Books or videos like "Learning Python", "Learn Python the Hard Way", 
or the Coursera/EdX classes cover what the publisher felt could be 
covered in a profitable way.


3. Books like "Python Projects" can help someone go from absolute newbie 
to being able to do useful stuff. 


When I was learning Ruby I put section dividers in a 3 ring binder and 
had one section for each of the topics in the Pickaxe book. That way as 
I learned and relearned things could gel a little better. I have an old 
copy of "Learning Python" and will break out the section dividers today.


I don't know about anyone else, but I have a bad habit of jumping in way 
over my head and getting frustrated when I can't make things work. By 
setting a sequential list it helps prevent that; learning Objects is 
much easier when one understands functions.



documentation. It's sort of the "if we hired a junior or senior coder, what
basics would we want them to know?"


That's the thing. I've never, in 40 years in IT, seen
anyone advertise for a junior programmer. Just doesn't seem to
happen. It's a bit like having a headache and asking for a
weak pain killer...

There are places offered for programming apprenticeships,
but they assume you are starting from scratch.



The PHP community has a Mentoring thing (https://php-mentoring.org/), 
and I would assume there are many open source Python projects that would 
be willing to bring a junior in and help them grow. Growth and 
contributing seem to go hand in hand. It's easy to read a book and think 
you "know" a language. It's more challenging when you're in the lab with 
seasoned programmers and you're pushed to produce better and better code.


It's a lot nicer for the seasoned programmers if you don't have to be 
convinced to write tests or taught what an object is.  :)


The "junior" level is more a gift to the seasoned programmers; someone 
who can do those basics has proven a willingness to learn coding past 
the "type what's in the book" phase. Of course, one must go through 
junior to get to senior.


For those interested, GIAC has a Certified Python Programmer. It focuses 
on using security tools, which is GIAC's forte.


http://www.giac.org/certification/python-coder-gpyc

Does a certification make you a better coder? Not really, there are lots 
of uncertified (but probably certifiable!) expert coders out there. 
However, certifications can help in the job search and it's nice to get 
paid for what you enjoy.


Leam




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


Re: [Tutor] Learning Objectives?

2017-02-27 Thread leam hall
On Mon, Feb 27, 2017 at 9:28 AM, Alan Gauld via Tutor 
wrote:

> On 27/02/17 10:44, Leam Hall wrote:
> > Is there a list of Python skill progression, like "Intermediates should
> > know  and Advanced should know ?" Trying to map out
> > a well rounded study list.
>
> I'm not aware of such a list, and I'm not sure it's of much value.
> Better to just learn what you need and use it. When you need
> to learn more, learn it. The worst thing you can do is study an
> arbitrary list of topics that don't have any relevance to
> the problems you need to solve!
>
> Nobody is going to ask for an intermediate programmer, or a
> beginner programmer. They might ask for an expert, but if you
> are really an expert you will know that already - and you
> won't be able to become one by studying anything extra.
>
> Once you are past the basics - ie. you can write a program
> that does something useful, it's all about writing code and
> learning as you go. And you never stop learning.
>
>
> Hey Alan!

When I was coming up as a Linux guy I took the old SAGE guidelines and
studied each "level" in turn. It was useful for making me a well-rounded
admin and helped me put off some higher end stuff I wasn't really ready
for.

Things like Testing and documentation are useful, but only learning what
seems to bee needed for this one project seems harder for the new coder.
Most of us didn't know TDD was useful until we started doing it. Same for
documentation. It's sort of the "if we hired a junior or senior coder, what
basics would we want them to know?"

Thanks!

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


[Tutor] Learning Objectives?

2017-02-27 Thread Leam Hall
Is there a list of Python skill progression, like "Intermediates should 
know  and Advanced should know ?" Trying to map out 
a well rounded study list.


Thanks!

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


Re: [Tutor] Good approach regarding classes attributes

2014-09-09 Thread leam hall
On Tue, Sep 9, 2014 at 9:09 AM, Sydney Shall  wrote:

> And while I am writing, what does OP stand for in this list?

"Original Poster". So I understand. Won't answer the Python question
since I'm a newbie here myself.

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


Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Fri, Aug 29, 2014 at 5:16 PM, Peter Otten <__pete...@web.de> wrote:
> leam hall wrote:
>
>> Am I asking the wrong question? How do older apps with older versions
>> of python (2.4.x) separate code into sub-directories? Do they?

> You have to ensure that the *parent* of alpha is in sys.path. Then you can
> refer from alpha/beta/one.py to alpha/gamma/two.py with the statement


Ah, so I can use sys.path.insert()! That's what I needed, thanks!

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


Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
Am I asking the wrong question? How do older apps with older versions
of python (2.4.x) separate code into sub-directories? Do they?

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


Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Fri, Aug 29, 2014 at 9:39 AM, diliup gabadamudalige
 wrote:
> this is the easiest way to do this
>
> # one.py is in the \data\ directory
> # two.py is in the \data\img\ directory
> # three.py is in the \data\img\sc\ directory
>
> ## this program is in the learn_music dir
>
> ## expanding the file path add a . before the new dir
>
> ## each directory you need to load a module from needs to have __init__.py
> file inside the directory. It can be an empty file but it needs to be there.
> That's how python knows that you can load a module from this directory. my
> one.py, two.py and three.py modules each have a string called a in it. You
> can have classes or functions which can be called in the same way.
>
> from data import one  # / data/
> from data .img import two  # /data/img/
> from data .img.sc import three  # /data/img/sc/
>
> print one.a, two.a, three.a
>
> hope this helps


So far this doesn't work. I'm pretty convinced it's either a Python
version issue (2.4.3 and 2.6.6.) or pure Operator Error. Leaning
towards the latter.

Thanks!

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


Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Thu, Aug 28, 2014 at 6:39 PM, Cameron Simpson  wrote:
> On 28Aug2014 22:36, Alan Gauld  wrote:
>>
>> On 28/08/14 19:03, leam hall wrote:
>>>
>>> python 2.4.3 on Red Hat Linux.
>>>
>>> I'm starting a project and want to break the scripts into "input",
>>> "output", and "ddl". I'd like to have a "lib" library directory for
>>> local modules. The library directory would be at the same level as the
>>> others.
>>>
>>> How do I get the library modules?
>>
>>
>> Add lib to the sys.path list?
>>
>> That may not be viable if you need it to be portable across systems,
>> although using os.getcwd to locate the current folder or an
>> environment variable to store the app root folder might be
>> options there.

The code will be imported to other machines so whatever I'm doing must
be portable. Right now my code looks like this:

###
## lib/mymodule.py

#!/usr/bin/env python

def howdy():
print("in mymodule")

###
## input/test_lib.py

#!/usr/bin/env python

from ..lib import mymodule
mymodule.howdy()

###
## Directory tree:
.
./input
./input/__init.py__
./input/test_lib.py
./lib
./lib/mymodule.py
./lib/__init.py__
./output


## In input, running test_lib.py
 ./test_lib.py
Traceback (most recent call last):
  File "./test_lib.py", line 3, in 
from ..lib import mymodule
ValueError: Attempted relative import in non-package


## the __init.py__ files are empty.


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


Re: [Tutor] Import from project's lib directory?

2014-08-28 Thread leam hall
On Thu, Aug 28, 2014 at 3:27 PM, Danny Yoo  wrote:
>>
>> Fails on both Python 2.4 and 2.6 with either ".lib" or "..lib".
>>
>> ### code
>> #!/usr/bin/env python
>>
>> from ..lib import mymodule
>> 
>>
>> In python/ddl, referencing ../lib/mymodule.py
>>
>>  ./import_test.py
>> Traceback (most recent call last):
>>   File "./import_test.py", line 3, in 
>> from .lib import mymodule
>> ValueError: Attempted relative import in non-package
>
>
> The word "package" has a technical meaning.  Here's a description:
>
> https://docs.python.org/2/tutorial/modules.html#packages
>
> Can you use packages to structure your code directory?  You'll need
> "__init__.py" files in the directories that are to be treated as
> packages.
>
>
> If you can structure your program into packages, then intra-package
> imports should work:
>
> https://docs.python.org/2/tutorial/modules.html#intra-package-references

I put empty __init.py__ files in both directories and a few parents.
Still no go.

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


Re: [Tutor] Import from project's lib directory?

2014-08-28 Thread leam hall
On Thu, Aug 28, 2014 at 2:19 PM, Danny Yoo  wrote:
> On Thu, Aug 28, 2014 at 11:03 AM, leam hall  wrote:
>> python 2.4.3 on Red Hat Linux.
>>
>> I'm starting a project and want to break the scripts into "input",
>> "output", and "ddl". I'd like to have a "lib" library directory for
>> local modules. The library directory would be at the same level as the
>> others.
>>
>> How do I get the library modules?
>>
>>   import '../lib/mymodule'
>
>
> You're looking for relative imports:
>
> https://docs.python.org/2.5/whatsnew/pep-328.html
>
> So for your case, perhaps:
>
> from ..lib import mymodule
>
> Alternatively, perhaps refer to the modules by toplevel package
> instead of relative path?


Fails on both Python 2.4 and 2.6 with either ".lib" or "..lib".

### code
#!/usr/bin/env python

from ..lib import mymodule


In python/ddl, referencing ../lib/mymodule.py

 ./import_test.py
Traceback (most recent call last):
  File "./import_test.py", line 3, in 
from .lib import mymodule
ValueError: Attempted relative import in non-package


 ls ../lib
mymodule.py


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


[Tutor] Import from project's lib directory?

2014-08-28 Thread leam hall
python 2.4.3 on Red Hat Linux.

I'm starting a project and want to break the scripts into "input",
"output", and "ddl". I'd like to have a "lib" library directory for
local modules. The library directory would be at the same level as the
others.

How do I get the library modules?

  import '../lib/mymodule'

Fails on syntax.

Thanks!

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


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-15 Thread leam hall
On a totally side note, I'm watching this because I want to do my own
starship stuff. Long time Traveller player.

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


Re: [Tutor] Better way to check *nix remote file age?

2014-06-27 Thread Leam Hall

On 06/27/14 06:10, Raúl Cumplido wrote:

Hi,

I would recommend also instead of doing an "ls -l" command doing
something to retrieve only the information you need:

/bin/ls -ls | awk '{print $7,$8,$9, $10}'

Jun 27 10:36 my_file


Then I would use timedelta instead where you can be more accurate with
the dates (in the example if the file is older than 62 days):
def too_old(text):
 month, day, year = (text[0], text[1],
 text[2] if ':' not in text[2] else
datetime.datetime.now().year)
 time_difference = datetime.datetime.now() - datetime.datetime.strptime(
 "{0}{1}{2}".format(month, day, year), '%b%d%Y')
 return time_difference > datetime.timedelta(days=62)



Raúl, that looks interesting. Let me think through it.

Leam

--
http://31challenge.net
http://31challenge.net/insight

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


Re: [Tutor] Better way to check *nix remote file age?

2014-06-27 Thread Leam Hall

On 06/27/14 17:40, Walter Prins wrote:

Hi,

On 26 June 2014 18:01, leam hall  wrote:

On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins  wrote:

On 26 June 2014 14:39, leam hall  wrote:

Python 2.4.3
Is there a better way to do this?

I'd probably rather try Paramiko's SFTPClient and retrieve the file

Seem to not work on Python 2.4.3.


What exactly did you try, and what error/output did you get?  (I've
had another look at Paramiko's homepage and it seems to support back
to Python 2.2? [http://www.lag.net/paramiko/ ])

Walter


Walter, I was cranky. Sorry.

When I looked at ( http://www.paramiko.org ) it specified Python 2.6+ 
and 3.3+. That's echoed in the README ( 
https://github.com/paramiko/paramiko/blob/master/README ) I have not 
actually tested to see what breaks on a 2.4 box.


The other option was to copy in the files and stat them. Trying to build 
a script that can be extended and not hit so much network bandwidth. The 
good thing about the way this is currently going is that a co-worker 
gave me a better Solaris solution that let me standardize the script for 
both Red Hat Linux and Solaris. Still need to figure out AIX.


The possibility exists to build a python outside of the standard. The 
issue is supportability. Like many others I'm a contractor and need to 
make sure whatever I do is so boringly simple that I can train my 
replacement. On one hand, that's a good thing. If people use my scripts 
after I'm gone then hopefully they won't cuss too much.


Since my exciting plans for the weekend have been canned I'll take a 
little time and think about how best to do this. Some of it is "what 
should I do with my career" type thinking. Some is just "hey, how does 
this work?".


Thanks for not responding as poorly as I did.

Leam

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


Re: [Tutor] Better way to check *nix remote file age?

2014-06-27 Thread leam hall
On Fri, Jun 27, 2014 at 7:41 AM, Stefan Behnel  wrote:

> Raúl Cumplido, 27.06.2014 12:10:
> > I would recommend you to migrate your Python version for a newer one
> where
> > you can use fabric, paramiko or other ssh tools. It would be easier.
>
> +1
>
> Even compiling it yourself shouldn't be too difficult on Linux.
>
>

I'm not retro just for the heck of it. There's no reason to avoid Python
3.x but sometimes you just have to work with what you have.

Anyone willing to provide a couple million dollars and 12-18 months of free
24/7/365.25 support?  I have to work with four different operating systems
and three of the four have two versions. Most might have python installed
but some don't. My code has to be clean enough that people new to Python
can understand it when something goes south.

Somewhat sorry for the rant. I just get tired of people saying "upgrade"
when that's not an option.

Leam

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


Re: [Tutor] Better way to check *nix remote file age?

2014-06-26 Thread leam hall
On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins  wrote:

> On 26 June 2014 14:39, leam hall  wrote:
> > Python 2.4.3
> >
> > Writing a function that takes the string from "ssh  ls -l
> > /var/log/yum.log" and tries to see if the file is more than a couple
> months
> > old. The goal is to only run python on the local server and it will ssh
> into
> > the remote server.
> >
> > Is there a better way to do this?
>
> I'd probably rather try Paramiko's SFTPClient and retrieve the file
> modified date directly:
>
> http://paramiko-docs.readthedocs.org/en/latest/api/sftp.html#paramiko.sftp_client.SFTPClient
> (see the SFTPFile.stat() method in particular, which gives you back a
> stat object containing mtime, the modification datetime IIRC)
>
> 2 more (hopefully) useful links if you decide to go this route:
> http://www.saltycrane.com/blog/2010/02/python-paramiko-notes/
>
> http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different
>
>
> Walter
>


Seem to not work on Python 2.4.3.

-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Better way to check *nix remote file age?

2014-06-26 Thread leam hall
Python 2.4.3

Writing a function that takes the string from "ssh  ls -l
/var/log/yum.log" and tries to see if the file is more than a couple months
old. The goal is to only run python on the local server and it will ssh
into the remote server.

Is there a better way to do this?

Thanks!

Leam



Standard type of string that would come in date_string:

New file:
  -rw---  1 sam users105 Jun 19 13:57 guido2

Old file:
  -rw---  1 sam users105 May 19 2011 guido





def linux_too_old(date_string):
'''(string) -> boolean

Returns True if the date string is more than a couple months old.

'''

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec']
this_month = datetime.date.today().month

file_date = date_string.split()

if ':' not in file_date[7]:
return True

file_month = file_date[5]

if 0 < (this_month - months.index(file_month)) < 3:
return False




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


Re: [Tutor] Real world experience

2014-05-12 Thread leam hall
On Mon, May 12, 2014 at 1:47 PM, Danny Yoo  wrote:

> >> I have never known anyone that works in this industry.
>
> Just as a side comment: there are probably several folks on this
> mailing list whose job description would match "working in industry".
>

One big step is "program for someone else". Whatever you do scratches your
own interests and itches. Once you start programming for someone else's
changing requirements and lack of understanding of coding limitations you
really find out if you "know" the language.

Leam

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


Re: [Tutor] One on one tutor

2014-04-05 Thread Leam Hall

On 04/04/2014 07:49 PM, Keith Adu wrote:

Hi my name is Keith, am a beginner with no experience in python or computer 
science. Am looking for someone to work with me one on one, I have many 
question that I need answered, my question are basic as of the moment because 
am starting, I don't want to send an email to everyone about my questions 
because I feel it will be a waste of their time. If you are interested please 
let me know. Thank you for reading this.


Good morning Keith!

There is no education like self-education! Alan's Python tutorial 
(http://www.alan-g.me.uk/) is a great place to start. If you just ask 
questions you will probably not learn as much as if you try and then ask 
specific questions.


This is a beginner's list; people expect you to ask beginner questions. 
However, some might be a bit short in their answers if you have not at 
least tried to figure out the problem on your own. You will not really 
learn to program, either.


Try. Fail. Explain the problem to yourself. Fail again. Ask the list for 
help when you can really explain the problem.


Leam

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


[Tutor] System output into variable?

2014-04-03 Thread leam hall
I've been trying to so a simple "run a command and put the output into a
variable". Using Python 2.4 and 2.6 with no option to move. The go is to do
something like this:

my_var = "ls -l my_file"

So far the best I've seen is:

line = os.popen('ls -l my_file', stdout=subprocess.PIPE, shell=True)
(out, err) = line.communicate()

With no way to make 'my_file' a variable.

I've got to be missing something, but I'm not sure what. Python has always
impressed me a a language without a lot of hoops to go through.

Leam

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


[Tutor] How to get file permissions (Python 2.4)?

2014-03-19 Thread leam hall
I can use os.chmod('/usr/local/somefile') to change permissions but I
haven't been able to find a way to test for file modes.

>>> stat.S_IRWXU('/usr/bin/python')
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: 'int' object is not callable

What should I be looking for? Python 2.4.3 (RHEL 5)

Thanks!

Leam

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


Re: [Tutor] Which computer operating system is best for Python

2014-02-06 Thread leam hall
On Thu, Feb 6, 2014 at 8:38 AM, Neil Cerutti  wrote:

> Linux is a great OS for a child to learn computing and
> programming on, provided the parent knows it well enough to train
> the student on it. If not, it's just inviting needless headaches.

Look at http://www.edubuntu.org/

Leam

---

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


Re: [Tutor] Best version for novice

2014-02-02 Thread Leam Hall

On 02/01/2014 03:35 PM, Alan Gauld wrote:

On 01/02/14 18:41, Ian D wrote:


Is it better to use python 3 as a newcomer who isn't really going to be
writing any software as such just using it for learning?


The more important question is which version does your
preferred tutorial use?


And are you targeting a specific platform or just for yourself? Some 
platforms, like Red Hat/CentOS, are still 2.x. The most current RHEL is 
2.6 and the upcoming RHEL 7 is still Python 2.7.


If you're doing this for yourself, or for a start-up that can use newer 
versions, use 3.x if your tutorial supports it. You might note in Alan's 
signature is a like to his site, which happens to have a nice tutorial.   :)


http://www.alan-g.me.uk/

Leam

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


[Tutor] subprocess.Popen help

2014-01-28 Thread leam hall
Python tutorial for 2.6 (using 2.4 -- don't ask), first code blurb under 17.1.1

http://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#subprocess.Popen

How would you make an ssh to another box put data back in "p"? The
goal is to run a shell command on a remote box and work with the
output on the local host.

Thanks!

Leam

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


Re: [Tutor] Global var not defined?

2013-08-27 Thread leam hall
Well, I'm happy to change things but my python is only so good. And much of
that is based off of shell programming.

What the data looks like is fairly simple. I have a spreadsheet of host
information. Customer 'Alan' may have a dozen or so servers and customer
Ramit has another dozen or two. When I print these out they will be sorted
by customer but rolled into a single file.

The line "host_list[cust] = {}" creates the customer dictionary if that
customer doesn't exist. Then there's a host key with multiple layers:

   host_list['alan']['webserver']['ip'] = '12.23.34.45'
   host_list['alan']['webserver']['environ'] = 'Dev'

Make sense? As I do not know a lot about classes I'm not sure they are
better in this case than a multi-level dictionary. The data does not get
altered, just organized.

Leam


On Tue, Aug 27, 2013 at 2:34 PM, Prasad, Ramit wrote:

> leam hall wrote:
> > Could use some help with this. Python 2.4.3 on RHEL 5.x.
> >
> > In the functions file that gets imported:
> >
> > def append_customer(line_list):
> > global customers
> > cust = line_list[0] // list with Customer info in [0]
> > cust = clean_word(cust)  // Trims white space
> >
> > if len(cust) and cust not in customers:
> > host_list[cust] = {}
> > customers.append(cust)
> >
> > In the calling file:
> >
> >
> > import functions
> > import sys
> >
> > customers = []
> >
> > .
> > .
> > .
> > for line in input_file:
> > line = line.strip()
> > if not len(line):
> > continue
> > line_list = line.split(',')
> > functions.append_customer(line_list)
> >
> > Error message:
> > Traceback (most recent call last):
> >   File "./host_tools.py", line 55, in ?
> > functions.append_customer(line_list)
> >   File "/home/lhall/lang/functions.py", line 27, in append_customer
> > if len(cust) and cust not in customers:
> > NameError: global name 'customers' is not defined
> >
> >
>
> The problem is because "customers" needs to be defined
> in the module with the append_customers. Global as
> written refers to module level variables.
>
> Some (possible and untested) methods to get around this are:
> 1. pass in customers as an argument
> 2. use globals()?
> 3. add it to functions module `functions.customers = customers`.
>
>
> ~Ramit
>
>
>
> 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.
>



-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Global var not defined?

2013-08-27 Thread leam hall
Could use some help with this. Python 2.4.3 on RHEL 5.x.

In the functions file that gets imported:

def append_customer(line_list):
global customers
cust = line_list[0] // list with Customer info in [0]
cust = clean_word(cust)  // Trims white space

if len(cust) and cust not in customers:
host_list[cust] = {}
customers.append(cust)


In the calling file:

import functions
import sys

customers = []

.
.
.
for line in input_file:
line = line.strip()
if not len(line):
continue
line_list = line.split(',')
functions.append_customer(line_list)


Error message:
Traceback (most recent call last):
  File "./host_tools.py", line 55, in ?
functions.append_customer(line_list)
  File "/home/lhall/lang/functions.py", line 27, in append_customer
if len(cust) and cust not in customers:
NameError: global name 'customers' is not defined



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


Re: [Tutor] How much in a "try" block?

2013-08-23 Thread leam hall
Well, maybe I'm looking at the wrong construct. The script needs to open up
one file that will be on the machine. It will open up other files given as
command line arguments and open files to write to. It should fail
gracefully if it cannot open the files to be read or written. The community
that will use the script has varying levels of scripting but not hordes of
Python. I'd prefer to fail with an explanation so they could fix the issue
and not just blame the script.

Leam



On Fri, Aug 23, 2013 at 6:55 AM, Chris Down  wrote:

> On 2013-08-23 01:30, Alan Gauld wrote:
> > Unless you really only want g(x) executed if there is no MyError
> exception
> > but want h(x) executed regardless.
>
> I've had that situation a few times before when using the logic "try this,
> or
> fall back to this if it doesn't work".
>
> > I'm curious, how often do others use the try/else combination?
>
> Rarely. I think I've only used it twice in recent memory.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


[Tutor] How much in a "try" block?

2013-08-22 Thread leam hall
If I have a series of tasks that depend on X happening, should I put them
all in the same "try" block or just put X in there and exit out if it fails?

Thanks!

Leam


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


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread leam hall
The only question I have is what is compelling about being different than
other lists? Far as I can tell, most reply to the list if you click reply.

It's not something to get religious over; if I reply and don't have time to
make sure it goes to those who might be interested, at least it will go to
the person I'm responding to. They can forward it on if it's important
enough.  :)

Leam


On Tue, Aug 20, 2013 at 3:47 PM, Brian van den Broek <
brian.van.den.br...@gmail.com> wrote:

>
> On Aug 20, 2013 3:04 PM, "Andy McKenzie"  wrote:
> >
> > On Tue, Aug 20, 2013 at 2:53 PM, Alan Gauld 
> wrote:
> >>
> >> On 20/08/13 13:15, Andy McKenzie wrote:
> >>
> >>> Yep.  Someone decided it didn't make sense for "reply" to go to the
> list
> >>> that sent the message
> >>
> >>
> >> Lists never send messages. People do.
> >>
> >> So reply goes to the *person* who sent the message.
>
> 
>
> > The problem is, as far as I'm concerned the message came from the list.
> Needing to go to the dropdown and select "Reply to all" is just one extra
> movement, and it's one I have to make every single time I reply.  In all
> honesty, I can't think of a single time that I've wanted to reply to just
> the original sender:  that's the point of a mailing list, to have
> conversations on it.  I've occasionally been prompted to remember that I
> wanted to ask an individual something specific off-list, but it's never
> been a direct response to what was posted ON the list.
>
> 
>
> > It's basically a practicality thing for me.  On a list where the vast
> majority of replies went to the original sender, I'd agree with you.  For
> something like this, it's just making me do extra work without providing me
> with an extra benefit.
>
> Hi all,
>
> Alan's argument seems compelling, but is principled, thus perhaps
> vulnerable to a `practicality beats purity' response.
>
> What tips me against reply to munging is the principle of least damage,
> itself eminently practical.
>
> Imagine the non-actual possible world where this list reply munges and in
> which I wished to write Andy directly to cast aspersions on Alan's
> character and ancestry out of a misguided belief that reply to munging is
> right. I hit reply and shortly afterwards realize that I am missing toes.
>
> In the actual world, I might have accidentally sent this solely to Andy
> out of inattention. Irksome, but I still have all 7 of my toes.
>
> Powerful software often can and ought allow one to shoot oneself in the
> foot. It ought not however be designed so that in one context, doing what
> is safe and normal in another context surprisingly points a firearm at your
> feet without the accompaniment of klaxons and lights. (And even then …)
>
> Best,
>
> Brian vdB
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread leam hall
Replying to the human, vice the list, is about 99% never what I want. With
a 1% margin of error.  :)

Leam



On Tue, Aug 20, 2013 at 3:00 PM, Chris “Kwpolska” Warrick <
kwpol...@gmail.com> wrote:

> On Tue, Aug 20, 2013 at 8:53 PM, Alan Gauld 
> wrote:
> > On 20/08/13 13:15, Andy McKenzie wrote:
> >
> >> Yep.  Someone decided it didn't make sense for "reply" to go to the list
> >> that sent the message
> >
> >
> > Lists never send messages. People do.
> >
> > So reply goes to the *person* who sent the message.
> > Which is what mail always does, to modify it for mail
> > forwarded by a list server makes no sense whatsoever.
> > And it breaks the ability to send to the originator.
>
> The From: field still contains an e-mail address of a human.  Just
> copy-paste it into the To: field of your reply.
>
> And replying to the human instead of the list is almost never what you
> want.
>
> --
> Chris “Kwpolska” Warrick 
> PGP: 5EAAEA16
> stop html mail | always bottom-post | only UTF-8 makes sense
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] python tutoring

2013-08-20 Thread leam hall
Trent,

You can do well with Alan's on-line pages (
http://www.freenetpages.co.uk/hp/alan.gauld/) and just ask questions here.
The biggest thing is to pick a big enough but not too big project. Using
Python as your first programming language will spoil you, though, it's a
great language and covers a lot of options.

Leam


On Tue, Aug 20, 2013 at 10:52 AM, Prasad, Ramit <
ramit.pra...@jpmorgan.com.dmarc.invalid> wrote:

> Fowler, Trent wrote:
> >
> > Hello,
> >
> > Not long ago I came across the website of a professional programmer
> offering python tutoring services:
> >
> > http://www.jeffknupp.com/python-tutoring/
> >
> > I have attempted to contact him because I am interested but I've been
> unable to get in touch.  I was
> > wondering if anyone knew of people offering similar services.  I am a
> self-starter and highly
> > motivated, but I live in a small town in South Korea and I don't have
> any friends who program.  Since
> > I also don't have a computer science background and python is my first
> language, I really need someone
> > who can help me with the beginning stages.  Often times when I run into
> a problem not only do I not
> > know how to solve it, I don't even know how to ask the questions that
> will help someone else solve it.
> >
> > I don't want to be spoon-fed, just gently nudged and guided.  I'm on a
> budget but I'd be willing to
> > pay for a good teacher.  Preliminary googling has turned up precious
> little, so I thought someone here
> > might be able to point me in the right direction.
> >
> > Thanks,
> >
> > -Trent.
>
> Why not just post your questions on here? I mean, that *is* the purpose
> of this list. There are some very excellent tutors on here which has
> the advantage of not being limited to only one tutor's level of experience.
> Not to mention it is free. :)
>
> I would recommend reading
> http://www.catb.org/esr/faqs/smart-questions.html,
> posting in plain text and bottom or in-line posting.
>
> In general, try and reduce the amount of code to the smallest example you
> can.
> Provide Python version, operating system, code, input, expected output,
> actual output, and any exceptions with full trace (copy and paste the full
> message, not paraphrasing or retyping).
>
>
>
> Ramit
>
>
>
> 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
>



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


[Tutor] [OT] Replies go to individuals, not the list?

2013-08-19 Thread Leam Hall

All,

Am I more confused than normal or if I click "Reply" should it go just 
to the sender instead of the list?


Leam

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


[Tutor] Coursera Python Course starts today

2013-08-19 Thread Leam Hall

Hey all,

In case I'm not the absolute last person to know, the newest edition of 
the Coursera "Learn to Program" course started today. It is Python 
based, free, lasts 7 weeks, and pretty fun. I didn't get a certificate 
last time as life got in the way. Hope to succeed this time.


https://class.coursera.org/programming1-002/class/index

Leam


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


Re: [Tutor] Input into lists?

2013-08-16 Thread leam hall
Hey Dave, you're right. I worked through this with a for loop and set the
contents of a dict's key as the input.

Thanks!

Leam


On Thu, Aug 15, 2013 at 8:28 PM, Dave Angel  wrote:

> leam hall wrote:
>
> > I'm trying to take input from a file (CSV spreadsheet) and use the first
> > line inputs (header) as the names of lists. So far I'm not successful.
> :)
> >
> > How do I take line_list[0], the result of "line.split(',')" and use it as
> > the name of a list? Does that make sense?
> >
>
> No, it doesn't make sense.  You're trying to define a variable that has
> a name determined not by your source, but by a name in line 0 of the csv
> file.  How then are you going to use that variable?
>
> There are two possibilities:  Either you actually know those names and
> are using them in your code, or the names won't be known till runtime.
>
> If the latter, then make a dictionary of lists,
>
> mydict = {}
> for item in line_list:
> mydict[item] = []
>
> and then populate those lists from each line of the file.
>
> Now, if you're sure you know what the names are to be, then:
>
> names = mydict["name"]
> addresses = mydict["address"]
>
> or whatever.
>
>
>
>
> --
> DaveA
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple Python SNMP ping?

2013-08-16 Thread leam hall
One of the things I forgot to mention is that my host is using Python 2.4
and net-snmp 5.3; both packaged by a major North American Linux vendor.  :)

So there doesn't seem to be a native net-snmp tool set for these versions.
I'll poke around and see what else can be done.

Thanks!





On Fri, Aug 16, 2013 at 12:06 AM, Chris Down  wrote:

> Hi Leam,
>
> On 2013-08-14 15:21, leam hall wrote:
> > Is there a way to do a simple check in Python to see if a remote host is
> > listening on SNMP port 161/UDP?
>
> "Simple" in this case could either mean technically simple (in which case,
> use
> a socket with SOCK_DGRAM and wait for data) or implementationally simple
> (in
> which case, use an SNMP library). I'd only recommend doing the latter.
>
> Since UDP is stateless, you'll need to make sure that your destination
> replies
> with something, which means you probably need to send a real SNMP request.
> Since that's the case, you should really just use a real SNMP library
> (although
> I fear that your meaning of "simple" was "not using an SNMP library",
> which is
> really not simple at all.
>
> net-snmp[0] can do this fairly trivially, anyway. The following works for
> me:
>
> >>> import netsnmp
> >>> var = netsnmp.Varbind('sysDescr.0')
> >>> netsnmp.snmpget(
> ... var,
> ... Version=2,
> ... DestHost="localhost",
> ... Community="pub",
> ... )
> ('OpenBSD',)
>
> Best,
>
> Chris
>
> 0: http://www.net-snmp.org/wiki/index.php/Python_Bindings
>



-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple Python SNMP ping?

2013-08-15 Thread leam hall
Is there a way to do a simple check in Python to see if a remote host is
listening on SNMP port 161/UDP?

Thanks!

Leam

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


Re: [Tutor] Posting solutions to "homeworky" problems

2013-08-15 Thread leam hall
I've just started some of the Euler stuff. Most of the time I ask for
pointers to the logic needed. I enjoy that much more as hopefully I learn
something.

Leam

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


[Tutor] Input into lists?

2013-08-15 Thread leam hall
I'm trying to take input from a file (CSV spreadsheet) and use the first
line inputs (header) as the names of lists. So far I'm not successful.   :)

How do I take line_list[0], the result of "line.split(',')" and use it as
the name of a list? Does that make sense?

Thanks!

Leam

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


[Tutor] Fwd: Hello, and a newbie question

2013-04-16 Thread leam hall
Python 2.x if you're working on existing servers like RHEL. If you're
having fun on a desktop, Python 3.

Free on-line college level class just started:
https://class.coursera.org/interactivepython-002/class/index

BTW, PHP ROCKS!  :P

Leam
  -- Also a PHP programmer


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


Re: [Tutor] Starting a simple python project

2013-03-24 Thread Leam Hall

On 03/22/2013 05:02 AM, miguel.gua...@hushmail.com wrote:

Greetings all!


My name is Miguel Guasch, I'm a software tester who's trying to
slowly get into automation, and eventually (in a couple of years)
into development.


Miguel, welcome!

Depending on your skills, you might want to look up the Python classes 
on Coursera.org. They are free, challenging, and some offer a 
certificate of achievement. That might be useful in your work portfolio 
when you move to developer.


Last year's videos for one beginner class are still on-line:
https://class.coursera.org/programming1-2012-001/class/index

The follow up class for that starts tomorrow:
https://www.coursera.org/course/programming2

There's an introductory class starting in a few weeks:
https://www.coursera.org/course/interactivepython

And a Programming Design class starts in May:
https://www.coursera.org/course/programdesign

Note that I'm not affiliated with Coursera, except to take their 
classes. Of course, I'm a believer in open education, too.


Leam

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


Re: [Tutor] Python version 2.7 or 3.0

2013-03-12 Thread Leam Hall

On 03/12/2013 11:47 AM, Alan Gauld wrote:

On 12/03/13 14:20, Mike Nickey wrote:


I'm seeing on StackOverflow that 2.7 is the standard for those that have
libraries that haven't been ported to 3.1.2 yet. Does this mean that 2.7
is dead or dying? Is this just a well managed marketing campaign?


Like any software the latest version will eventually predominate. But
since many libraries have not been ported to v3 yet 2.7 is still very
much alive and still being supported. I seem to recall it being stated
that 2.7 is the last of the v2 Python family but that it will be
receiving updates/fixes for some time yet.

It's not a marketing campaign but the normal process of migrating from
one version to a newer, incompatible, version.


It also depends on what platform you're developing for. On Red Hat boxes 
2.6.6 is the "standard" for RHEL 6. From what I understand, RHEL 7 will 
not be Python 3 yet, either.


If you don't have any platform restrictions, then 3.3 is the way to go.

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


[Tutor] SMTP('my.smtpserver.com') hangs

2013-03-09 Thread Leam Hall

Python 2.6.6 on CentOS 6

I'm in section 3.4.12 of Wesley Chun's "Core Python Applications 
Programming". The POP3 stuff works but I can't seem to get the SMTP to 
connect, it just hangs and then times out. Running it in IDLE gets the 
same thing. Have also tried with the port # set, as well.


Thoughts?

Leam



#!/usr/bin/env python

from smtplib import SMTP
from poplib import POP3
from time import sleep

SMTPSVR = 'my.smtpserver.com'
POP3SVR = 'my.smtpserver.com'

who = 'm...@smtpserver.com'


user = 'me+smtpserver.com'
pass_ = 'my_super_secret'

body = '''\
From: %(who)s
To: %(who)s
Subject: test e-mail

Hello world!
''' % {'who' : who }

send_svr = SMTP(SMTPSVR)
errs = send_svr.sendmail(who, [who], body)
send_svr.quit()

assert len(errs) == 0, errs

print "Starting sleep"

sleep(10)

recv_svr = POP3(POPSVR)
recv_svr.user(user)
recv_svr.pass_(pass_)
rsp, msg, siz = recv-svr.retr(recv_svr.stat()[0])
recv_svr.quit()
sep = msg.index('')
recv_body = msg[sep+1:]
recv_svr.quit()
assert body == recv_body
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Civil discourse from a newbie's perspective

2012-10-02 Thread leam hall
My own struggles to better communicate, and to have my message heard,
supports the concerns raised here. The Python community is a very good one
and we are only made better by treating people well. it is easy to go to
other lists where I am a newbie and find top posting preferred and other
behavior encouraged.

Does the welcome e-mail cover any of the recommended behavior? Are there
easier ways to request participation within guidelines?

Leam

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


[Tutor] [Semi-OT] Yes or no on using a Graphical IDE?

2012-09-15 Thread leam hall
Hey all, not trying to contribute to the flames of one graphical IDE over
another. I'm just trying to figure out if they are worth the learning
curve? I have been doing most of my work in vi and the graphical IDE I'm
supposed to use for a class keeps adding crap that I have to erase, and I
have to move my hands to use the GUI parts instead of just typing.

Is there a point in which a GUI IDE becomes more of a help than a hindrance?

Thanks!

Leam

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


Re: [Tutor] Help with class in class

2012-09-09 Thread leam hall
self.blue = Button(root, text="Blue",
command=self.change_text_color("blue"))
self.blue.pack(side=LEFT)
self.green = Button(root, text="Green",
command=self.change_text_color("green"))
self.green.pack(side=LEFT)

To follow up, I've added a second button. Of course, it doesn't work, the
text comes out as the color of the last button. It is running the commands
in the Button line without the buttons being clicked.

More research...


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


Re: [Tutor] Help with class in class

2012-09-09 Thread leam hall
On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten <__pete...@web.de> wrote:

> the above will no longer complain about a missing attribute.
>
> > root = Tk()
> > project = ch8_Project(master=root)
> > project.mainloop()
>
>
> Another problem that caught my attention:
>
> > self.green = Button(root, text="Green",
> command=self.change_text_color("green"))
>
>
> The command argument is supposed to be a function; you are instead
> assigning
> the result of a method call (which is None in this case, but as a side
> effect will set the color to green immediately. The simplest fix is to
> define a helper function that takes no arguments
>  ...
>  def change_to_green():
>  self.change_text_color("green")
>  self.green = Button(root, text="Green", command=change_to_green)
>  ...
>
> If you already know about lambda you can try to rewrite this using that.
>
>
Peter, thank you for helping me understand the scope issue I was missing! I
knew it was something like that but forget that omitting "this." meant the
variables were limited in scope to that method.

I have seen lamba but do not understand it. The project requires four
buttons, each one turns the same text a different color. The class is also
Python 3 based.  :)

Leam



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


Re: [Tutor] Help with class in class

2012-09-09 Thread leam hall
Of course, showing the code might help...

 http://bpaste.net/show/44593/

Thanks!

Leam

On Sun, Sep 9, 2012 at 10:42 AM, leam hall  wrote:

> I'm in the O'Reilly Python 2 class, so pointers to learning would be
> better than just answers, please. My brain is a bit slow but needs to go
> forward.
>
> Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out
> why I get
>
>   File "./ch8_project.py", line 31, in change_text_color
> self.text.tag_configure('highlightline', foreground=fg_color)
> AttributeError: 'ch8_Project' object has no attribute 'text'
>
> If line 31 starts with "self." and
>
>   File "./ch8_project.py", line 31, in change_text_color
> text.tag_configure('highlightline', foreground=fg_color)
> NameError: global name 'text' is not defined
>
>
> If Line 31 does not start with "self.". I understand the second problem
> but not the first.
>
> What am I missing?
>
> Thanks!
>
> Leam
>
>
> --
> Mind on a Mission <http://leamhall.blogspot.com/>
>
>


-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with class in class

2012-09-09 Thread leam hall
I'm in the O'Reilly Python 2 class, so pointers to learning would be better
than just answers, please. My brain is a bit slow but needs to go forward.

Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out
why I get

  File "./ch8_project.py", line 31, in change_text_color
self.text.tag_configure('highlightline', foreground=fg_color)
AttributeError: 'ch8_Project' object has no attribute 'text'

If line 31 starts with "self." and

  File "./ch8_project.py", line 31, in change_text_color
text.tag_configure('highlightline', foreground=fg_color)
NameError: global name 'text' is not defined


If Line 31 does not start with "self.". I understand the second problem but
not the first.

What am I missing?

Thanks!

Leam


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


Re: [Tutor] help me decide

2012-09-04 Thread leam hall
Matthew,

Program what is fun for you. I prefer PHP for web work but I'm learning
Python for my day job. Python provides a wider range of abilities but PHP
is more "fun" for me. If Python GUIs are fun, then do that. The more you
enjoy the topic the more reason you will have to learn more and more. I
doubt you will exhaust Python's capabilities any time soon.

Python or Java? For me it's Python. The only real Java advantage might be
Android programming.

Leam


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


[Tutor] Getting name of Widget for event.widget?

2012-07-25 Thread Leam Hall
Note that this is for an on-line class so I'd appreciate pointers to 
what I need to read or think about more than the answer out right.


Using Python 3 on Linux, is there a way to get the name of a widget 
instead of numeric representations in event.widget?


What I tried were a few variations of:

def small_frame_handler1(self, event):
print(event.widget, " clicked at ", event.x, event.y)

and got:

.140937484.144713004  clicked at  350 39

Called by:

   frame1 = Frame(self, bg="blue")
   frame1.grid(row=0, column=0, rowspan=1, columnspan=2, sticky=ALL)
   frame1.bind("", self.small_frame_handler1)

I tried to send parameters in the "bind" but kept getting argument 
mis-matches. There are two frames and I'd like to be able to put the 
name of the frame in the print without having to have a separate method 
for each one. This is inside a class, if that makes a difference.


Thanks!

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


Re: [Tutor] Where do I start developing from?

2012-07-20 Thread leam hall
Santosh,

It is fun to try new activities. Maybe implement some of the PHP
things you did in Python. I find myself making small games or tools
for games when I want to try something out.

You might also want to work with Eclipse and some of the IDE tools, as
well as learn Unittesting and stuff like that.

Leam

On 7/20/12, Santosh Kumar  wrote:
> Hello There,
>
> First time I came in contact with Python programming languages was
> nearly 1 year (I am learning this languages from my home). Prior to
> this I was good at PHP, HTML and CSS (this doesn't mean that I want to
> say that I wanted to become a web developer). I have read many books
> and tutorial that which were available for free
> ,
> ,
> .
>
> Now I feel bored to learn more and want to implement my knowledge
> somewhere. I have no idea what to do, I probably won't program a
> software from starch. I want to test how much I am up to. So, where
> can I start?
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


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


Re: [Tutor] While learning Py: To IDE or not to IDE?

2012-05-20 Thread Leam Hall

On 05/20/2012 06:19 PM, boB Stepp wrote:

On Sun, May 20, 2012 at 4:44 PM, Brian van den Broek

I am an emacist, myself. But some of my best friends are vimists.


Will pray for your soul...


But since you brought it up, I'll ask a somewhat more general
question: Why do you prefer an editor instead of a graphical IDE?


Because I work on a Winderz desktop at work but have to connect to my 
servers via ssh. So terminal enabled programs are better for me.


Because my hardware at home is so old that your average Gameboy has more 
computing power and better graphics.


Because I'm too cheap to pay for much of anything I can't touch.

And mostly because I don't make myself program as much as I want to and 
spend what little time coding actually in the code. Since I claim to 
want to be a programmer I need to do programmer stuff.


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


Re: [Tutor] Multiple DBs per application?

2012-05-14 Thread Leam Hall

On 05/14/2012 06:44 PM, Alan Gauld wrote:

On 14/05/12 20:33, leam hall wrote:

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?



No, you can usuially have multiple databases open at once.
You can have multiple instances of the same database or
different database types.

However the data types are rarely ta reason to use different databases.
More typically would be different performance requirements or security
issues. For example it's common to hold some data in an LDAP structure
for speed of access (at the expense of flexibility) and the rest of the
data in an RDBMS such as MySql. But using say MySQL and Oracle together
would normally only be done because they were pre-existing datastores
from another project.


Thanks! I was more thinking of something like a CMS where user login 
information and admin functions might be in a SQLite database and then 
some larger backend big data stuff in MongoDB or similar. Just wasn't 
sure if there was a basic flaw to the idea that I wasn't aware of.


Leam

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


[Tutor] Multiple DBs per application?

2012-05-14 Thread leam hall
All,

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?

Thanks!

Leam

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


Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

2012-05-01 Thread Leam Hall

On 05/01/2012 08:02 PM, Santosh Kumar wrote:

Its getting complicated now. Will it effect or not?
Give me one word answer with one line description.


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


Re: [Tutor] Is there a way I can print the output of help(module)?

2012-04-27 Thread Leam Hall

On 04/27/2012 03:11 PM, Joel Goldstick wrote:


Hey Steven, thanks.

I guess I was a little lazy in my research.  I just discovered pydocs
before I read your response.  Its great!  This is great motivation to
write concise and complete docstrings.



Joel, I am constantly amazed by all the things Python offers. Enjoy the 
language!


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


[Tutor] Problem Stripping

2012-03-30 Thread leam hall
Python 2.4.3 on Red Hat 5. Trying to use strip to remove characters
but it doesn't seem to work like I thought.


res = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE)
uname = res.stdout.read().strip()

>>> uname
'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011
i686 i686 i386 GNU/Linux'

>>> uname.strip(':')
'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011
i686 i686 i386 GNU/Linux'

>>> 'www.example.com'.strip('cmowz.')
'example'

Thoughts?

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


Re: [Tutor] Any book to study Python

2012-03-28 Thread Leam Hall

On 03/28/2012 02:40 PM, wesley chun wrote:


hi xianming,

any of the tutors here can help you, not just me! :-)




once you provide the server code and output, people may be able to
help you better.

best regards,
-- wesley


Agreed. It depends on firewalls between the two IP addresses. Also, the 
Linux server may have IP tables installed which might prevent access to 
that port but allow ping.


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


Re: [Tutor] 答复: Any book to study Python

2012-03-19 Thread Leam Hall

On 03/19/2012 09:36 PM, Yan, Xianming wrote:

Hello Russel,

Thanks for your recommendation and reply.


...

Xianming,

Wesley is a great help here as is Alan Gauld. One of the things I really 
like about the Python language is the experts who still help us new 
programmers.


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


Re: [Tutor] dict vs several variables?

2012-02-18 Thread Leam Hall

On 02/18/2012 03:39 AM, Peter Otten wrote:

Leam Hall wrote:


On 02/17/2012 09:26 AM, Dave Angel wrote:

There are two ways to think of a class. One is to hold various related
data, and the other is to do operations on that data. If you just
consider the first, then you could use a class like a dictionary whose
keys are fixed (known at "compile time").


I think a class is the way to go for a couple reasons. First, of course,
is that it pushes me to learn more. It also lets me encapsulate a lot of
the work into one thing and keep the methods there.


One word of caution. If you make just one do-it-all class with a single
instance and use instance attributes as if they were global variable the
improvement over the global dictionary is minimal. You still should strive
to make dependencies explicit, e. g. prefer

def add(a, b): return a + b

over

class DoItAll:
 def add_a_and_b(self):
 self.c = self.a + self.b


Understood. In this case I'm starting the application and there are two 
separate bits. I'm studying tkinter for the class I'm in so the GUI 
stuff is one module and the formulas are in another module. The reason I 
considered a global dict or a class is because all of the data bits are 
directly related.


Dave angel wrote:

class MyDiver(object):
def __init__(self, depth, gasmix, time, rate):
self.depth = int(depth)
self.gasmix = int(gasmix)
self.time = datetime.datetime(time)
self.rate  = float(rate)

Which is a pretty good start, makes me think he's done scuba before.  :)

The object in question is a scuba dive. The user types in how deep they 
want to go, what gas mix they are on, how long they plan on staying, and 
what they think their air consumption rate will be. The formulas 
calculate absolute atmospheres which are used in other formulas, O2 
concentration (a risk factor), how much of the daily increased O2 
exposure the dive will create, and how much gas is needed to make that 
dive.


If the program grew the only thing that might be pulled out is the air 
consumption rate. That would likely go into a diver object so there was 
a profile for each diver. However, at the moment the app is just giving 
you dive profile information so you can plan your bottom time and gas 
consumption.


That's my thinking as of this morning. I need to go back and build 
unittests; will do so while moving it into a class. Should be fun and 
good learning!


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


Re: [Tutor] dict vs several variables?

2012-02-17 Thread Leam Hall

On 02/17/2012 09:26 AM, Dave Angel wrote:

There are two ways to think of a class. One is to hold various related
data, and the other is to do operations on that data. If you just
consider the first, then you could use a class like a dictionary whose
keys are fixed (known at "compile time").


I think a class is the way to go for a couple reasons. First, of course, 
is that it pushes me to learn more. It also lets me encapsulate a lot of 
the work into one thing and keep the methods there.


Thanks!

Leam

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


Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
On 2/17/12, Peter Otten <__pete...@web.de> wrote:
> leam hall wrote:
>> and they may have to have their type set
>
> I have no idea what you mean by "have their type set". Can you give an
> example?

Peter,

The variables input seem to be assumed to be strings and I need them
to be an integer or a float most of the time. Doing simple math on
them.

Thanks!

Leam

-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
On 2/17/12, Dave Angel  wrote:

> Real question is whether some (seldom all) of those variables are in
> fact part of a larger concept.  If so, it makes sense to define a class
> for them, and pass around objects of that class.  Notice it's not
> global, it's still passed as an argument.  This can reduce your
> parameters from 20 to maybe 6.  But make sure that the things the class
> represents are really related.
>
> Dictionaries are a built-in collection class, as are lists, sets, and
> tuples.  But you can write your own.  An example of needing a class
> might be to hold the coordinates of a point in space.  You make a
> Location class, instantiate it with three arguments, and use that
> instance for functions like
> move_ship(ship, newlocation)
>
> DaveA

Understood. In this case, the first half dozen variables are input and
the rest are derived from the first ones. A class might make sense and
though I understand them a little, not enough to make a good judgement
on it.

The task is to take parameters for a scuba dive; depth, gas mix, time,
air consumption rate, and compute the O2 load, gas required, etc.

Leam

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


Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
Thanks Peter!

My concern with variables is that they have to be passed in specific
order to the function, and they may have to have their type set
multiple times so that you can perform the right functions on them. In
a dict you could set it on insert and not have to worry about it.

Thanks!

Leam

On 2/17/12, Peter Otten <__pete...@web.de> wrote:
> Leam Hall wrote:
>
>> I'm building a program that uses one of my own modules for a bunch of
>> formula defs and another module for the tkinter GUI stuff. There are
>> half a dozen input variables and about the same in calculated variables.
>> Is it better/cleaner to just build a global dict and have everything go
>> into it or pass multiple arguments to each function and have it return
>> the calculated value?
>
> The latter. It makes the dependencies explicit to a reader of the function,
> it simplifies unit tests, allows it to reuse functions in a different
> context, and it is more likely to work in a multi-threaded environment.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Mind on a Mission <http://leamhall.blogspot.com/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dict vs several variables?

2012-02-17 Thread Leam Hall
I'm building a program that uses one of my own modules for a bunch of 
formula defs and another module for the tkinter GUI stuff. There are 
half a dozen input variables and about the same in calculated variables. 
Is it better/cleaner to just build a global dict and have everything go 
into it or pass multiple arguments to each function and have it return 
the calculated value?


Thanks!

Leam

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


Re: [Tutor] specific recommendation for a Python book, to move from baby-level to intermediate-level

2012-02-15 Thread leam hall
I will have to agree with both Wes and Alan, they provide great
resources. However, the issue you will face is three-fold. You need
to:

1. Write lots of good code.
2. Write lots more good code.
3. Show a whole lot of good code you've written.

If you want to program professionally I suggest getting a job in
computers that is near where you want to be. Develop your programming
skills and your work reputation at the same time. Your porfolio of
lots of good code will require more than one language, software
lifecycle and version control, specification writing,
etc...etc...etc...

To write good code you need books, experience, and lots of critical
review. Otherwise you'll be writing lots of bad code that won't get
you anywhere. Feedback is critical to growth.

Leam

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


Re: [Tutor] Moving from snippits to large projects?

2012-01-09 Thread leam hall
On 1/9/12, Mike G  wrote:
>  How does one go from small to medium, to large, as a coder? 
>
> You might look into contributing to an existing project.
>
> There is a new project, MediaLocker, a Python / wxPython app recently
> underway, started from a blog post. I
> believe they are looking for input, including contributing - have a look.
>
> http://www.medialocker.pythonlibrary.org/

Mike,

Media locker looks interesting, thanks!

Leam


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


Re: [Tutor] Moving from snippits to large projects?

2012-01-09 Thread Leam Hall

Leam Hall wrote:

>> Steve and Hugo Responded

> To which Leam Replies:

Thanks! The O'Reilly class has twelve lessons, the first two are on unit 
testing. The rest of them will enforce tests be written for their 
projects.  :)


I'll look at Git and Sourceforge in the next couple days. In theory I'd 
like to get to kernel programming so Git would be useful. However, it 
doesn't have the Software Lifecycle tools Sourceforge has.


One of the problems with Python is that the neat things I'd like to 
write and use are already written! Well, there are things I need to 
learn, like Sphinx, Twisted, and maybe CherryPy. As well as PDB and 
better unittests.


So much to learn! I'm happy...

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


[Tutor] Moving from snippits to large projects?

2012-01-08 Thread Leam Hall
I'm taking the O'Reilly Python 2 course on-line, and enjoying it. Well, 
when Eclipse works, anyway. I'm still getting the hang of that.


While my coding over the years has been small snippits in shell, PHP, 
and a little C, python, and perl, I've never made the transition from 
dozens of lines to hundreds or thousands. I'd like to start working on 
that transition but the projects I know about are much larger than my 
brain can handle and there are a lot of other corollary tools and 
practices to learn.


How does one go from small to medium, to large, as a coder? Large 
projects, that is. I've gotten the "large as in too much pizza" thing 
down.  ;)


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