groupby - summing multiple columns in a list of lists

2011-05-17 Thread Jackson
I'm currently using a function pasted in below. This allows me to sum
a column (index) in a list of lists.

So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]]
group_results(mylist,[0],1)

Returns:
[(1, 5), (2, 7)]

What I would like to do is allow a tuple/list of index values, rather
than a single index value to be summed up, so you could say
group_results(mylist,[0],[1,2]) would return [(1, 5,7), (2, 7,9)] but
I'm struggling to do so, any thoughts? Cheers

from itertools import groupby as gb
from operator import itemgetter as ig

def group_results(table,keys,value):
res = []
nkey = ig(*keys)
value = ig(value)
for k, group in gb(sorted(table,key=ig(*keys)),nkey):
res.append((k,sum(value(row) for row in group)))
return res
-- 
http://mail.python.org/mailman/listinfo/python-list


selecting base class from user input

2006-08-13 Thread Jackson
I want a class that will determine its base class by the argument passed
in.  What I am about to write _does_not_work_, but it shows what I am
trying to do.

class ABC(some_super):
def __init__(self,some_super):
some_super.__init__(self)

if some_super == list:
   self.append('ABC')

elif some_super == dict:
   self['ABC'] = None


Then, the user can call this function:

>>> example = ABC(list)
>>> print example
['ABC']

>>> example = ABC(dict)
>>> print example
{'ABC': None}

Clearly, this is a bad example, but the central idea is what I am trying
to do.  ABC is a particular example which can be represented in various
forms.  I want an ABC class that will create the example in the form
specified by the user.

So how can I achieve this? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: selecting base class from user input

2006-08-14 Thread Jackson
Thanks for the reply.

danielx wrote the following on 2006-08-13 19:49:
> Is your declaration of ABC supposed to have some_super as one of the
> base classes? Your constructor has some_super as a parameter. What is
> this supposed to mean in light of the declaration for ABC?

Indeed, my goal is to have the base class of ABC determined dynamically
via a parameter passed into the constructor.
> 
> If you are trying to customize the base class of ABC by passing an
> argument to the constructor of ABC, you should probably reconsider. If
> constructing one instance of ABC can change ABC (the class) itself,
> then the behavior of other instances will be affected as well. No
> programmer can stay sane if he creates instances of a class that could
> suddenly change its behavior (due to someone else's code).

Fortunately, the ABC class is not very useful.  In fact, it was mostly
just to be used to store particular examples of the user-specified base
class.  So all method calls would be from the base class only.

> 
> What you could do instead is to create a function which constructs
> classes based on the arguments it recieves. Then, you'll be able to
> create instances of the generated classes (all this meta-thinking is
> huring my brain ;). I am talking about something like this:
> 
> def createClass(name, base):
>   exec "class %s(%s): pass" % (name, base)
>   return eval( "name" )

In fact, this is exactly what I ended up doing.

def example(base):
  if base == SomeClass:
# call SomeClass.__init__(self)
# build example as it would look in SomeClass

  elif base == SomeOtherClass:
# call SomeOtherClass.__init__(self)
# build example as it would in SomeOtherClass

> Can you please tell us why you are doing this? My curiosity is killing
> me!
> 

So here is a good example:

I have 4 classes:

Lion(Animal):
Ant(Animal):
Bee(Animal):
Human(Animal):

which are all subclasses of some superclass called Animal.  Now I want
to define an occupation. For example, Worker.  A worker can exist as any
of the 4 classes above.  Their constructors are different and I might
want to add certain features.

My first thought was to create a class called "Worker" and have the base
class determined by a variable which is passed into the constructor.
Most of the method calls will come from the Animal superclass anyway,
but some method calls might come from the Lion class, for example.

Now I realize this would drive a programmer crazy...because a Lion might
have a roar() method whereas a Human might have a holler() method. But
so long as the user knew which argument they passed in, it shouldn't be
too difficult to keep track of it.

So for example (again, I know what I am typing doesn't actually work)...

Worker(some_animal):
  def __init__(self,some_animal):
# change the base class to some_animal

if some_animal == Lion:
# give the lion a big mane

if some_animal == Ant:
# make the ant dumb

if some_animal == Bee:
# make the bee know how to dance

if some_animal == Human
# give the human a hardhat

  def work(self, hours):
# tell the animal to work for the specified number of hours
if some_animal == Lion:
self.cat_nap(hours)
if some_animal == Ant:
self.walk_back_and_forth(hours)
if some_animal == Bee:
self.buzz_and_dance(hours)
if some_animal == Human:
self.use_hammer_on_coworker(hours)
# notice, a Human does not have a cat_nap method

  def take_lunch(location):



and so on. So the thought is that a Worker can exist in many different
forms: as a lion, as an ant, as a bee, and as a human.  And I might want
a single worker class that represents them all.

Hopefully this makes sense.

> Another meta-thought: Hopefully I've beaten everyone else to the punch
> about that question. Is it just me, or will a reply with such a
> question always tell the original poster that what he wants to do MUST
> be flawed? I hope I have been gentler than this.
> 

:-) There is no need to be too gentle.  We are all here to learn (or
help).  So I am fairly happy with the def solution...any comments on
this? But a Worker is an noun, and it seems like the proper way to do
this is to make the Worker into a class...so that I can define methods
like "work", "take_lunch", etc.  However, I have no idea how I should do
this.  Perhaps someone can recommend a procedure.

thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: selecting base class from user input

2006-08-14 Thread Jackson
Maric Michaud wrote the following on 2006-08-14 01:26:
> In [28]: class Animal(object) :
>: _types = {}
>:
>:
> 
> In [29]: class Worker(object) :
>: def work(self) : print 'hard'
>:
>:
> 
[snip]
> What you are trying to achieve is more commonly done by agregation and 
> delegation :
> 
> In [47]: class Lion(Animal) :
>: def __init__(self, *classes) :
>: self._objects = tuple(c() for c in classes)
>: def isA(self, class_) :
>: return class_ in (type(o) for o in self._objects)
>: def __getattr__(self, name) :
>: for obj in self._objects :
>: try: return getattr(obj, name)
>: except: pass
>: raise AttributeError('not defined or found in objects "%s"' 
> % 
> name)
>:
>:
> 
> In [48]: Lion().work()
> ---
> exceptions.AttributeErrorTraceback (most recent 
> call last)
> 
> /home/maric/
> 
> /home/maric/ in __getattr__(self, name)
> 
> AttributeError: not defined or found in objects "work"
> 
> In [49]: Lion().isA(Worker)
> Out[49]: False
> 
> In [50]: Lion(Worker).isA(Worker)
> Out[50]: True
> 
> In [51]: Lion(Worker).work()
> hard
> 

This is exactly what I am looking for.  However, I am not sure how to
implement different Worker methods.  For example, a Lion might work
differently than an Bee. In my example, the Lion would take a cat-nap
while the Bee might do a dance.

It seems that I would need to what kind of class called the work()
method.  Is there a way to do that?

Even if I could do that, it seems these various definitions of work
should probably go into the class of the animal---so that Lion actions
are all within the Lion class.  Thus, the Lion class should have its own
work method, and the Bee class should have its own work method as well.
 The problem with this is that every Lion can use the work method, when
I really only work Workers to use the work method.

I can picture another way of achieving this...have a list of
occupations...which are booleans for each instance of the class.  Then
the work() method will call only if the Worker boolean is True.  This
should be sufficient...and the differing work methods would be in their
respective classes. However, now the actual method names are not
uniform---that is, it becomes a bookkeeping exercise to remember that
when Worker is True, then the method to create is work(), that when
Student is True, then the method to create is study().  So this
procedure has its own problems too.  It seems like I am trading off
hardships now.

So here is what I am looking for:

A single Worker class with a standardized set of method names. The
methods in the Worker class are dependent on the "superclass" (via
aggregation and delegation, as shown above) of the worker.  That is, a
Bee performs different actions when working than a Lion or a Human.  And
finally, the occupations such that "not every Bee is a worker" and
"there are some Workers which are Bees".

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: selecting base class from user input

2006-08-14 Thread Jackson
John Machin wrote the following on 2006-08-14 01:45:
> Here are a couple of thoughts that *might* help:
> 
> (1) mix-in i.e. a class can have multiple base classes:
> 
> class AntWorker(Animal, Worker):
> 
> (2) you can create classes on the fly using the 3-argument form of the
> built-in type() function:
> 
> new_cls = type(name_of_class, base_classes_tuple, dict_of_methods_etc)
> 

This seems like it should work. The only problem I have with it is that
there are a _lot_ of classes to define (and remember).  For 256
different animals, we'd have to create 256 more animal-worker classes.
Obviously this works, but it seems not to be in the spirit of classes
and subclasses in that it doesn't (in some central way) highlight that
there is just one occupation: a worker.

As another example, suppose we had Shakespeare's Romeo and Juliet.  What
I mean is that we have the "idea" (the storyline, themes, etc) of Romeo
and Juliet. Further, suppose that we have various ways of expressing the
piece:  poem, book, movie, broadway.

It is true, we could do:

a = RaJPoem()
a = RaJBook()
a = RaJMovie()
a = RaJBroadway()

but it would be nice if we could do something like this:

a = RaJ(Poem)
a = RaJ(Book)
a = RaJ(Movie)
a = RaJ(Broadway)

And then a method call to RaJ might do something different for each
media. For example,

a.get_opening()

should fetch the opening of each media(first stanza, first chapter,
first scene, etc).  Thus, Poem, Book, Movie, and Broadway should
probably have a get_opening() method, and the RaJ class should pass this
call onto the respective class.  Notice, get_opening() is not exclusive
to RaJ.  Maric's method works nicely for this.

Additionally, I might want some methods which are exclusive to RaJ. For
example,

a.get_love()

would fetch elements of love from each type of media. Clearly this
method depends on the type of media. And there is not one method that
each media class could call.

For a poem, the RaJ class might look for a specific way that love can be
expressed (specific to RaJ). Studpid example, look for the word 'love'
at the end of each line.

For a movie, we might look for any scenes where the couple kisses.

The point is that there are methods for which the set of calls will
differ depending on the media type (poem, book, movie, etc).

This seems like a fun idea to me, and I'd like to think that things like
this are done frequently.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Difference between unindexable and unsubscriptable

2006-10-10 Thread Jackson
What is the difference between "object is unindexable" and "object is 
unsubscriptable"?

I would like to test if an object can accept:   obj[0]

 >>> from sets import Set
 >>> Set([1,2])[0]
TypeError: unindexable object

 >>> 3[0]
TypeError: unsubscriptable object

It seems like each of these errors can be replaced with a single type error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Vector Space Membership

2006-11-07 Thread Jackson
Is there a package which provides a VectorSpace object defined over the
Reals, Rationals, Complex, etc?  It'd be nice to test membership.
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheritance Question

2006-11-10 Thread Jackson
I've got an inheritance question and was hoping brighter minds could
guide me.  I am in the strange situation where some of the methods in a
subclass are actually more general than methods in a superclass.  What
is the preferred way to handle such situations.  My original thought was
to do something like this:

class AA(object):
def general_method(): pass

class A(AA):
   # redefine general_method() to call a
   # restricted version of AA.general_method()

class B(A,AA):
   # redefine general_method() to call AA.general_method()

This seems ugly to me, and I am wondering if there is a better method.
So any suggestions would be appreciated.


Thanks!






---

For a more "concrete" example:

Suppose all the animals in the world have only 1 or 2 legs.

class Legs(object)
  def run(): pass
  def walk(number_of_legs):
# lots of commands
# that do not depend on the
# number of legs but definitely
# have to do with walking

if number_of_legs == '1':
   # blah blah

if number_of_legs == '2':
   # blah blah

# more commands

class HasAtLeastOneLeg(Legs):
  def walk():
# Legs.walk(number_of_legs=1)

class HasTwoLegs(HasAtLeastOneLeg,Legs):
  def walk()
# Legs.walk(number_of_legs=2)

# isinstance(HasTwoLegs, HasAtLeastOneLeg) --> True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python game

2013-06-19 Thread Jackson Kemp
Thankyou this was very helpful
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: possible to run a python script without installing python?

2011-03-16 Thread David Jackson
i need to run a python script on any arbitrary server and don't want to do
an actual installation. i figured i could do a clean install on my machine
and install whatever libraries would be needed, then zip them all up for
remote deployment. to avoid bloating, i am wondering which files i can
safely omit.


On Tue, Mar 15, 2011 at 8:48 PM, Katie T  wrote:

>
> On Tue, Mar 15, 2011 at 8:58 PM, davidj411  wrote:
>
>> it seems that if I copy the python.exe binary and the folders
>> associated with it to a server without python, i can run python.
>> does anyone know which files are important to copy and which can be
>> omitted?
>>
>> i know about py2exe and have had no luck with it.
>
>
> What's the reason for wanting to avoid installing Python? - are you just
> trying to save disk space?
>
> If it's a case of not having admin rights, you can just copy the Python
> directory, I don't believe it has any dependencies anywhere else.
>
> Katie
> --
> CoderStack
> http://www.coderstack.co.uk
> The Software Developer Job Board
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to read file content and send email on Debian Bullseye

2023-02-05 Thread Jim Jackson
On 2023-02-05, ^Bart  wrote:
>> For example, try to do whatever parts you know how to do and when some part
>> fails or is missing, ask.
>
> You're right but first of all I wrote what I'd like to do and if Python 
> could be the best choice about it! :)

I'd say you want a simple shell script wrapped around your job, and a 
program to send email (bsdmail/sendmail or similar or mstmp on linux for 
instance).

>
>> I might have replied to you directly if your email email address did not
>> look like you want no SPAM, LOL!
>
> Ahaha! I think you know what is spam and what is a reply\answer to a 
> post request so you can feel free to use also my email! :)
>
>> The cron stuff is not really relevant and it seems your idea is to read a
>> part or all of a log file, parse the lines in some way and find a line that
>> either matches what you need or fail to find it. Either way you want to send
>> an email out with an appropriate content.
>
> You got the point!
>
>> Which part of that do you not know how to do in python? Have you done some
>> reading or looking?
>
> Like what I wrote above I didn't know if Python can does what I need and 
> if to use Python is a good way I'll start to study how to do it! :)
>
> In my past I used Python for Arduino programming or to do easy things, 
> what I should do now is little more complex but I understood from years 
> and years by the Python's powers you can do everything! LOL! :)
>
> Regards.
> ^Bart
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read file content and send email on Debian Bullseye

2023-02-05 Thread Jim Jackson
On 2023-02-05, ^Bart  wrote:
>> xdg-email appears to be for interactive use (it opens the user's
>> "preferred email composer"); I think sendmail would work much better
>> from a script.
>
> Like what I said in another post I think I could use ssmtp than 
> xdg-email or sendmail...
>
>> Otherwise, I had the same initial thought, to add to and/or build a
>> wrapper around the existing lftp script.
>
> I'd like to know if there's a code made from lftp to understand when an 
> upload file is finished

You make an lftp "script" to upload the file and write a log somewhere - 
write a script to run lftp with the lftp script, when the lftp has 
finished email the log. The log will show what happenned.

In cron run the script.

>  but certainly I can read it from the log file 
> and I think it couldn't be hard to find a value in a *.txt file and if 
> this value is inside of it to send an email like "ok" otherwise a 
> message with "k.o.".
>
> Regards.
> ^Bart
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding through recursion

2005-11-18 Thread Mark Jackson
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> There is problaly a really simple answer to this, but why does this
> function print the correct result but return "None":
> 
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
> x -= 1
> y += 1
> add(x, y)
> 
> print add(2, 4)
> 
> result:
> 6
> None

Perhaps this hint will help:

>>> print add(0,6)
6
6

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Of course a weed-puller isn't of much *use* in the Garden
of Eden, but it takes a while to figure that out.
- Tim Peters


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation suggestions

2005-12-07 Thread Mark Jackson
Steven Bethard <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
> > Iain> I like the Global Module Index in general - it allows quick access
> > Iain> to exactly what I want.  I would like a minor change to it though
> > Iain> - stop words starting with a given letter rolling over to another
> > Iain> column (for example, os.path is at the foot of one column, while
> > Iain> ossaudiodev is at the head of the next), and provide links to each
> > Iain> initial letter at the top of the page.
> > 
> > I know it's not what you asked for, but give
> > 
> > http://staging.musi-cal.com/modindex/
> > 
> > a try.  See if by dynamically migrating the most frequently requested
> > modules to the front of the section it becomes more manageable.
> 
> That's pretty cool.  What I don't know is how it would look after 
> thousands of people using it.  I know that I probably only have 10 
> modules or so that I consistently need to check the docs for.  Your hack 
> above would conveniently place those all at the top if I was the only 
> user.  But are those 10 modules the same 10 modules that other folks 
> need?  I don't know...
> 
> Of course, the only way to find out is to try...

Or you can just look up the module you need to write a 'bot to
constantly look up the docs for your favorite 10 modules. . . .

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
If it made sense, that would be a very powerful idea.
- Bruce Eric Kaplan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global variables

2005-02-03 Thread Mark Jackson
Steve Holden <[EMAIL PROTECTED]> writes:
> M.E.Farmer wrote:
> 
> > Ok it has been a long day,
> > In my reply to Steven Bethard , Steve should read Steven ;)
> > 
> > M.E.Farmer
> > 
> Well, since he signs himself "Steve" too I guess we'll just have to put 
> up with the ambiguities. Or perhaps, given my (lack of) typing skill, I 
> should just start signing myself "Stvev"?

What's this doing *here*?  I thought the discussion of the pitfalls of
name rebinding was taking place in the "variable declaration" thread.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
People who write obscurely are either unskilled in writing
or up to mischief.  - Sir Peter Medawar


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tricky Dictionary Question from newbie

2005-07-11 Thread Mark Jackson
"Ric Da Force" <[EMAIL PROTECTED]> writes:

> It is hard to explain but this is what I mean:
> 
> Dict = {'rt': 'This is repeated', 'sr': 'This is repeated', 'gf': 'This is 
> not'}
> 
> I want this to return a new dict with string keys and lists containing the 
> previous keys for repeated values.
> 
> NewDict = {'This is repeated':['rt','sr'],'This is not':['gf']}

NewDict = {}
for x in Dict.keys():
try:
NewDict[Dict[x]].append(x)
except KeyError:
NewDict[Dict[x]] = [x]

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
It is difficult for men in high office to avoid
the malady of self-delusion.- Calvin Coolidge


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interleave merge pdf files

2005-07-22 Thread Mark Jackson
"Chirayu Krishnappa" <[EMAIL PROTECTED]> writes:
> Hi,
> 
> I need to scan documents with pages having printed matter on both
> sides. It is easiest to stack them in the autosheet feeder and let it
> scan. I end up with one file (say A.pdf) containing the odd pages in
> sequence. Similarly, I can end up with B.pdf containing the even pages.
> I want to combine them into result.pdf which contains A.1, B.1, A.2,
> B.2, A.3, B.3, ... (A.1 = page 1 of A.pdf).
> 
> Does someone know a simple way to achieve this? I noticed the other
> thread on this newsgroup about merging lots of pdf files and
> multivalent tools and pdftk were mentioned. However, I could not find a
> way to do this using them. I am interested in another free tool or a <
> 25 lines python script (which may use any freeware library) to do the
> same.

I face exactly the same problem.  Based on examination of the pdftk man
page I *think* it can be done by something like (untested):

pdftk A.pdf burst output %04d_A.pdf
pdftk B.pdf burst output %04d_B.pdf
pdftk *_?.pdf cat output combined.pdf

assuming fewer than 10,000 pages per document, of course.

I would be interested in an alternative approach which does not
generate a ton of intermediate pdfs.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
It is difficult for men in high office to avoid
the malady of self-delusion.- Calvin Coolidge


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: negative integer division

2005-02-07 Thread Mark Jackson
Imbaud Pierre <[EMAIL PROTECTED]> writes:
> integer division and modulo gives different results in c and python, 
> when negative numbers
> are involved. take gdb as a widely available c interpreter
>   print -2 /3
> 0 for c, -1 for python.
> more amazing, modulos of negative number give negative values! (in c).
> from an algebraic point of view, python seems right, but I thought 
> python conformity to the underlying c compiler was a strong commitment, 

AIUI the C standard is silent on the issue, and hence the C behavior is
implementation-dependent.  Anyway back in 2000 I found and fixed a
Y2K-related problem in an open-source C program (xvtdl) which was down
to precisely this misbehavior.  While diagnosing the problem I
implemented the algorithm in Python for test purposes, and was led
astray for a while by the fact that it *didn't* fail!

A:  42

Q:  What multiple of 7 did I add to the critical expression in the Zeller
algorithm so it would remain nonnegative for the next few centuries?

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
People who write obscurely are either unskilled in writing
or up to mischief.  - Sir Peter Medawar


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: negative integer division

2005-02-10 Thread Mark Jackson
[EMAIL PROTECTED] (John Machin) writes:
> [EMAIL PROTECTED] (Mark Jackson) wrote in message news:<[EMAIL PROTECTED]>...
> > 
> > A:  42
> > 
> > Q:  What multiple of 7 did I add to the critical expression in the Zeller
> > algorithm so it would remain nonnegative for the next few centuries?
> 
> What are you calling "the Zeller algorithm", and what is the "critical
> expression"?

A C function in calendar.c, encountered in the source code for xvtdl:

int zeller (month, day, year)
int month, day, year;
{
  int century;
  month -= 2;   /* Years start on March 1 so adjust standard date */
  if (month < 1) {
 month += 12;
 year--;
  }
  century = year / 100;
  year = (int)year % (int)100;
  return ((int)((2.6 * month - 0.1) + day + year + year / 4  + century / 4 - 
century * 2) % 7);
}

The expression upon which "% 7" acts is negative when "year" is small.
This caused errors beginning in March 2000; which could be deferred by
adding a suitably-large multiple of 7 to the expression.  The choice
was obvious. :-)

> I've no doubt you came across a stuffed-up date-to-days calculation
> routine and fixed it, but it's a bit unfair to lumber Zeller with the
> blame. If it was a days-to-date routine, then Zeller is not even
> standing next to the real target.

Fair enough, although I'm not responsible for having named the function
(which appears to date from 1991).  The original author is identified
in the code (available at
http://www.alumni.caltech.edu/~mjackson/xvtdl.html) and is findable via
the Web; you might take the matter up with him.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
People who write obscurely are either unskilled in writing
or up to mischief.  - Sir Peter Medawar


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I get message filename from a Maildir mailbox stream?

2005-02-19 Thread Phil Jackson
[EMAIL PROTECTED] writes:

> Is there a way to figure out what filename an email object points to
> in a qmail style Maildir directory?

What do you mean bu "email object"? Surely if you are iterating a
Maildir then you should have the filename. Or am I misunderstanding
what you mean?

Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-23 Thread Phil Jackson
Tom Willis <[EMAIL PROTECTED]> writes:

> How are the expert pythoneers dealing with config files?

You could use the cPickle module if you don't mind your config files
being unreadable by humans. There is also the shlex module for more
powerful config file needs:

http://docs.python.org/lib/module-shlex.html

While I'm replying to you, would you mind if I take the opportunity to
ask you to stop top-posting?

Thanks,

Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework

2005-03-09 Thread Phil Jackson
"Gianluca Sartori" <[EMAIL PROTECTED]> writes:

> What web framework do you suggest to develop with?

I tend to use mod_python.

Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Mark Jackson
[EMAIL PROTECTED] (John Machin) writes:
> "Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
> PROTECTED]>...
> > Well I would suggest the Python in a Nutshell and the Python Cookbook  both 
> > by O'Reilly as references.  They are great for a desktop reference and I 
> > check them first before I google/search else where for answers.  Being they 
> > are reference books they or more on aide then a teaching device however I 
> > have learned from those books how to use certain standard classes, such as 
> > the re class for example. 
> 
> Somebody called O'Reilly taught you that Python has "standard
> classes", one of which is "re"??? Hmmm, can't have been O'Reilly the
> publisher; must have been O'Reilly the builder.

Or possibly O'Reilly the pundit.  Lucky he didn't tell you Python has
falafels.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
You should always save hyperbole until you really need it.
- Hobbes (Bill Watterson)


-- 
http://mail.python.org/mailman/listinfo/python-list


Strange extra f added to bytes object

2013-10-06 Thread Robert Jackson
I am very new to python so I'll apologize up front if this is some
boneheaded thing.  I am using python and pyserial to talk to an embedded
pic processor in a piece of scientific equipment.  I sometimes find the
when I construct the bytes object to write it adds an extra f to the first
byte.

For example if I have b'\x03\x66\x02\x01\xaa\xbb' it evaluates
to b'\x03f\x02\x01\xaa\xbb', which doesn't even seem valid.

Can anyone shine some light this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange extra f added to bytes object

2013-10-06 Thread Robert Jackson
Thank you all.  It was unfortunate that it was f since I thought it was
some strange mistaken hex nibble.  All very clear and helpful.



On Sun, Oct 6, 2013 at 9:07 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Sun, 06 Oct 2013 20:39:39 -0400, Ned Batchelder wrote:
>
> > When Python displays a string, is uses
>
> A byte string.
>
> > the ASCII character if it can, and a hex escape if it can't.  When you
> > use a hex value that is a valid ASCII character, it will display the
> > character.
>
> Obviously for Python 2 that behaviour can't change, but I am saddened
> that the opportunity to fix the display of byte strings in Python 3
> wasn't taken. In my opinion, it would have been much better if byte
> strings were always shown in hex. (They could also have a separate method
> for showing them in ASCII, if necessary, but even that is only one call
> to decode() away.)
>
> Displaying a *byte* string using ASCII by default just continues the
> confusion that many people have, that the character "f" is necessarily
> the same as the byte 0x66. *And* it leads to the OP's error, wondering
> why his byte-stream of 0x66... displays with a strange 'f'.
>
> If you ask me, including ASCII in the printable representation of byte
> strings in Python 3 is buggy by design :-(
>
>
> --
> Steven
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Filename case-insensitivity on OS X

2006-01-06 Thread Mark Jackson
Dan Lowe <[EMAIL PROTECTED]> writes:

> Think about it - how many things used by average people are case  
> sensitive? Passwords? That's about it. (And judging by most user  
> passwords I have seen, they're almost all lowercase anyway.) Email  
> addresses, URLs, the search box in Google, your AOL or Jabber buddy  
> list: all case-insensitive.

Not all URLs.  Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Those who can make you believe absurdities
can make you commit atrocities. - Voltaire


-- 
http://mail.python.org/mailman/listinfo/python-list


import

2006-07-05 Thread David Jackson
Hi all,

I'm a real beginner with python but have what I think is a simple question. 
I am writing some simple modules and would like to place them into a 
subdirectory.  But then I cannot seem to import them.  I have tried the 
following.

I wrote a module called fibo.py with some definitions in it (one called 
fibo).  In the same directory, I wrote another file (test.py) and began with 
import fibo.  This worked fine and I was able to use the function fibo as 
fibo.fibo.  Then, I made a directory called test and placed the file fibo.py 
in this directory.  I also placed a blank file called _init_.py into this 
directory.  I went back to the original directory and tried to import 
test.fibo but this fails.  I get the following error message:

Traceback (innermost last)
  File "...test.py", line 1, in ?
import test.fibo
  File "...test.py", line 1, in ?
import test.fibo
ImportError: No module named fibo

Any help would be greatly appreciated.  If it makes any difference, I'm 
working on a Mac, OSX 10.3.9

Thanks,
David 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import

2006-07-07 Thread David Jackson
Indeed you are correct...that is indeed TWO underscores and everything works 
fine now.  Thanks for pointing out the obvious...I thought it was a simple 
problem.  --DJ

"faulkner" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> that should be __init__.py [TWO underscores].
> and you might want to import sys and check sys.path [the list of
> directories searched by the import mechanism].
>
>
> David Jackson wrote:
>> Hi all,
>>
>> I'm a real beginner with python but have what I think is a simple 
>> question.
>> I am writing some simple modules and would like to place them into a
>> subdirectory.  But then I cannot seem to import them.  I have tried the
>> following.
>>
>> I wrote a module called fibo.py with some definitions in it (one called
>> fibo).  In the same directory, I wrote another file (test.py) and began 
>> with
>> import fibo.  This worked fine and I was able to use the function fibo as
>> fibo.fibo.  Then, I made a directory called test and placed the file 
>> fibo.py
>> in this directory.  I also placed a blank file called _init_.py into this
>> directory.  I went back to the original directory and tried to import
>> test.fibo but this fails.  I get the following error message:
>>
>> Traceback (innermost last)
>>   File "...test.py", line 1, in ?
>> import test.fibo
>>   File "...test.py", line 1, in ?
>> import test.fibo
>> ImportError: No module named fibo
>>
>> Any help would be greatly appreciated.  If it makes any difference, I'm
>> working on a Mac, OSX 10.3.9
>>
>> Thanks,
>> David
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


Why does wx.Window.CaptureMouse() send EVT_PAINT

2006-12-07 Thread Bill Jackson
It seems that the CaptureMouse method sends an EVT_PAINT handler.  The 
documentation does not mention this...is it somewhere else?  Could 
someone explain why this handler is sent out?

Also, I've seen:

 def OnMouseDown(self, evt):
 self.CaptureMouse()
 self.x, self.y = self.lastx, self.lasty = evt.GetPosition()
 self.Refresh(False)

Given that CaptureMouse initiates a repaint, isn't self.Refresh(False) 
moot at the point.

Thanks.  The doc for CaptureMouse are below.

-

CaptureMouse(self)

Directs all mouse input to this window. Call wx.Window.ReleaseMouse to 
release the capture.

Note that wxWindows maintains the stack of windows having captured the 
mouse and when the mouse is released the capture returns to the window 
which had had captured it previously and it is only really released if 
there were no previous window. In particular, this means that you must 
release the mouse as many times as you capture it, unless the window 
receives the wx.MouseCaptureLostEvent event.

Any application which captures the mouse in the beginning of some 
operation must handle wx.MouseCaptureLostEvent and cancel this operation 
when it receives the event. The event handler must not recapture mouse.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does wx.Window.CaptureMouse() send EVT_PAINT

2006-12-12 Thread Bill Jackson
Tim Roberts wrote the following on 12/09/2006 08:27 PM:
> The source code could answer that question for sure, but I doubt that it is
> CaptureMouse doing it, and I know the SetCapture API (which it eventually
> calls) does not.  Is it possible that your clicking caused some part of the
> app to become unhidden, or caused some button to change state?

Indeed. The EVT_PAINT came from self.Refresh(False).  I mistakenly 
thought that False implied that it would not refresh, but the docs 
clearly state (which I had not read) otherwise.  To reiterate, 
CaptureMouse does not send an EVT_PAINT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Which class's comparison function is called?

2007-06-05 Thread Bill Jackson
For example,

class A:
   def __init__(self,a):
 self.a = a
   def __eq__(self, other):
 return self.a == other.a

class B:
   def __init__(self,b):
 self.b = b
   def __eq__(self, other):
 return self.b == other.b


A(1) == B(1)
---> AttributeError: B instance has no attribute a

B(1) == A(1)
---> AttributeError: A instance has no attribute b

 From the above, it seems that Python always uses the function defined 
by the class on the LEFT.  However, I don't understand the following then:

A(1) == 3
---> AttributeError: 'int' object has no attribute a

3 == A(1)
---> AttributeError: 'int' object has no attribute a

Can someone explain this?  I expected 3 == A(1) to use the __eq__ 
function defined for 'int' objects.
-- 
http://mail.python.org/mailman/listinfo/python-list


Better dict of dicts

2007-04-19 Thread Bill Jackson
I have a dictionary of dictionaries where the keys are typically very 
long tuples and repeated in each inner dictionary.  The dictionary 
representation is nice because it handles sparseness well...and it is 
nice to be able to look up values based on a string rather than a 
number.  However, since my keys are quite long, I worry that I am 
wasting a lot of memory.  I'm looking for better data structures.

Here is an example:

 >>> a = {"string_1": {"string_2":1,
...   "string_3":5,
...   "string_4":10},
...  "string_2": {"string_2":12,
...   "string_6":2,
...   "string_1":4}}

So as my strings get longer and longer, it seems that the dictionary of 
dictionary representation is less and less efficient.

My thought was to subclass the dictionary structure

keys = {"string_1":1,
 "string_2":2,
 "string_3":3,
 "string_4":4,
 "string_6":5}

Then the underlying dictionary of dictionaries would look like:

a = {1:{2:1,3:5,4:10},2:{2:12,5:2,1:4}}

Somehow I need to intercept every possible call thoughsuch that

a["string_1"]["string_2"]   actually calls a[1][2]

and

a.keys()  returns ["string_1", "string_2", "string_3"]
   rather than [1,2,3,4,5]

etc.

Ideally, I would like the option to have different key hashes for the 
rows and columns as well.

Any ideas?


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Better dict of dicts

2007-04-19 Thread Bill Jackson
Martin v. Löwis wrote the following on 04/19/2007 02:43 PM:
> Bill Jackson schrieb:
>> I have a dictionary of dictionaries where the keys are typically very
>> long tuples and repeated in each inner dictionary. 
> 
> What I don't understand here: you say the keys are tuples, yet later,
> you show that the keys are strings. Which one is it?

Sorry, I was just lazy.  The keys will always be tuples...tuple of 
strings, tuples of numbers, tuples of objectssimply tuples.

> Instead of doing that, I would use a procedure called "interning".
> You may want to use the builtin intern function, or your can
> come up with your own interning:
> 
> interns = {}
> def local_intern(s):
>   return interns.setdefault(s, s)
> 
> Then, instead of
> 
> a[k1][k2] = value
> 
> do
> 
> a[local_intern(k1)][local_intern(k2)] = value
> 
> then all strings occur only once as keys, as long as the interns
> dictionary isn't cleared.
> 

So, my structure is something like this:

a = {tuple_1: {tuple_2:value_1, tuple_3:value_2},
  tuple_4: {tuple_1:value_3, tuple_3:value_4}
  tuple_5: {tuple_2:value_5, tuple_3:value_6, tuple_4:value_7}}

Since the tuples from the inner dictionaries and the outer dictionaries 
are frequently the same, I would benefit from using a single intern 
function. Then, the tuples will always be "pointing" to the values 
stored in the intern dictionary.

Now suppose there is little overlap between the keys for the outer 
dictionary and the inner dictionaries...but still much overlap between 
the various inner dictionaries.  Then, there is no point in using an 
intern function for the outer dictionary, but still a benefit for the 
inner dictionary.  Thus, something like the following would be appropriate:

a[k1][local_intern(k2)] = value

Have I understood this properly?
-- 
http://mail.python.org/mailman/listinfo/python-list


When to clear a dictionary...

2007-04-20 Thread Bill Jackson
What is the benefit of clearing a dictionary, when you can just reassign 
it as empty?  Similarly, suppose I generate a new dictionary b, and need 
to have it accessible from a.  What is the best method, under which 
circumstances?

 >>> import some_function

 >>> a = {1:2,3:4}
 >>> b = {1:2:4:3}
 >>> a.clear()
 >>> a.update(b)

 >>> a = {1:2,3:4}
 >>> b = {1:2,4:3}
 >>> for key in b:
... a[key] = b[key]

 >>> a = {1:2,3:4}
 >>> b = {1:2,4:3}
 >>> a = b

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When to clear a dictionary...

2007-04-20 Thread Bill Jackson
Bill Jackson wrote the following on 04/20/2007 09:48 AM:
>  >>> import some_function
> 
>  >>> a = {1:2,3:4}
>  >>> b = {1:2:4:3}
>  >>> a.clear()
>  >>> a.update(b)
> 
>  >>> a = {1:2,3:4}
>  >>> b = {1:2,4:3}
>  >>> for key in b:
>  a[key] = b[key]

Clearly, this won't have the same result as the other two examples.

> 
>  >>> a = {1:2,3:4}
>  >>> b = {1:2,4:3}
>  >>> a = b
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Preferred Random Library

2007-04-25 Thread Bill Jackson
Is there a preferred random library?

scipy.random
random

Besides scipy's library returning ndarrays, is there any other 
advantage/disadvantage?
-- 
http://mail.python.org/mailman/listinfo/python-list


random.py

2007-04-25 Thread Bill Jackson
In random.py (Python 2.5.1), line 86 says:

VERSION = 2# used by getstate/setstate

Then, in the definition of Random.setstate, we have:

if version == 2:

Why is it not:

if version == self.VERSION:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preferred Random Library

2007-04-25 Thread Bill Jackson
Paul Rubin wrote the following on 04/25/2007 10:17 PM:
> Bill Jackson <[EMAIL PROTECTED]> writes:
>> Is there a preferred random library?
> 
> Preferred for what?  Maybe you want os.urandom().

How about for general usage...I am just asking for a very broad 
description of the advantages/disadvantages of each.

For instance, what is the scipy.random equivalent of random.jumpahead()?

-- 
http://mail.python.org/mailman/listinfo/python-list


Import Problems

2007-04-27 Thread Bill Jackson
Once again, I am having issues with imports...

Until now, I thought the general guidelines were to rarely use 'from x 
import y' syntax, except when you really want to copy names over. 
However, I have run into issues by following this guideline.  So...

1) What is going wrong in the example below?
2) What is a good way to handle imports for packages w/subdirectories?

Here is a sample directory structure:

importtest/
   __init__.py
   test2/
 __init__.py
 someclass.py
 mytest.py


Here are the definitions of the files:

# importtest/__init__.py
from test2 import *

# importtest/test2/__init__.py
from someclass import *
from test2 import *

# importtest/test2/someclass.py
class SomeClass:
pass

# importtest/test2/mytest.py
import importtest
print importtest.SomeClass


On import I get the following:

 >>> import importtest
Traceback (most recent call last):
  File "", line 1, in ?
  File "/home/user/lib/python/importtest/__init__.py", line 1, in ?
from test2 import *
  File "/home/user/lib/python/importtest/test2/__init__.py", line 2, in ?
from mytest import *
  File "/home/user/lib/python/importtest/test2/mytest.py", line 3, in ?
print importtest.SomeClass
AttributeError: 'module' object has no attribute 'SomeClass'
 >>>


The problem seems to be an 'order' issue.  importtest/test2/__init__.py 
has loaded someclass.py, but it doesn't seem to have copied its contents 
into importtest/__init__.pyperhaps it is because it hasn't finished 
all of its imports.  Is this correct?

So what is a good way to deal with this?  In files which contain 
implementations, I thought it was best not to use 'from x import y', but 
this seems to be the only way to get this to work:

# importtest/test2/mytest.py
from someclass import SomeClass
print SomeClass

Is this the guideline?
   Use 'from x import y' for modules within your package.
   Use 'import y' for modules outside your package.

Help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Problems

2007-04-27 Thread Bill Jackson
Bill Jackson wrote the following on 04/27/2007 12:49 PM:
> # importtest/test2/__init__.py
> from someclass import *
> from test2 import *

Sorry typo here:

# importtest/test2/__init__.py
from someclass import *
from mytest import *
-- 
http://mail.python.org/mailman/listinfo/python-list


matplotlib, usetex

2007-05-25 Thread Bill Jackson
Hi, I'm having some trouble plotting with the following matplotlibrc:

   text.usetex : True

I tried clearing the cache files under ~/.matplotlib, but this did not 
help the problem. I'd post on the matplotlib mailing list, but I have a 
hard enough time browsing sourceforge's achives (frequent internal 
server errors).  Here is some output:


 example.py 
import pylab
pylab.plot(range(10))
pylab.show()


# python example.py --verbose-helpful
matplotlib data path /usr/share/matplotlib/mpl-data
$HOME=/home/me
loaded rc file /home/me/matplotlibrc
matplotlib version 0.87.7
verbose.level helpful
interactive is False
platform is linux2
numerix Numeric 24.2
font search path ['/usr/share/matplotlib/mpl-data']
CONFIGDIR=/home/me/.matplotlib
loaded ttfcache file /home/me/.matplotlib/ttffont.cache
backend GTK version 2.10.4
Traceback (most recent call last):
   File "example.py", line 2, in 
 pylab.plot(range(10))
   File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line 
2027, in plot
 ret =  gca().plot(*args, **kwargs)
   File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 
2131, in plot
 self.autoscale_view(scalex=scalex, scaley=scaley)
   File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 985, 
in autoscale_view
 self.set_xlim(XL)
   File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 
1227, in set_xlim
 self.viewLim.intervalx().set_bounds(xmin, xmax)
TypeError: only length-1 arrays can be converted to Python scalars.


The problem does not exist when text.usetex is False.  Ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib, usetex

2007-05-25 Thread Bill Jackson
Alexander Schmolck wrote the following on 05/25/2007 02:33 PM:
> (BTW what happens if you do axis([0,128,0,128])).

In [1]: import pylab

In [2]: pylab.axis([0,128,0,128])

In [3]: pylab.show()
---
   Traceback (most recent call last)

/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py in 
expose_event(self, widget, event)
 282 x, y, w, h = self.allocation
 283 self._pixmap_prepare (w, h)
--> 284 self._render_figure(self._pixmap, w, h)
 285 self._need_redraw = False
 286

/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py in 
_render_figure(self, pixmap, width, height)
 270 """
 271 self._renderer.set_width_height (width, height)
--> 272 self.figure.draw (self._renderer)
 273
 274

/usr/lib/python2.5/site-packages/matplotlib/figure.py in draw(self, 
renderer)
 542
 543 # render the axes
--> 544 for a in self.axes: a.draw(renderer)
 545
 546 # render the figure text

/usr/lib/python2.5/site-packages/matplotlib/axes.py in draw(self, 
renderer, inframe)
1061
1062 for zorder, i, a in dsu:
-> 1063 a.draw(renderer)
1064
1065 self.transData.thaw()  # release the lazy objects

/usr/lib/python2.5/site-packages/matplotlib/axis.py in draw(self, 
renderer, *args, **kwargs)
 559 tick.set_label1(label)
 560 tick.set_label2(label)
--> 561 tick.draw(renderer)
 562 if tick.label1On and tick.label1.get_visible():
 563 extent = tick.label1.get_window_extent(renderer)

/usr/lib/python2.5/site-packages/matplotlib/axis.py in draw(self, renderer)
 159 if self.tick2On: self.tick2line.draw(renderer)
 160
--> 161 if self.label1On: self.label1.draw(renderer)
 162 if self.label2On: self.label2.draw(renderer)
 163

/usr/lib/python2.5/site-packages/matplotlib/text.py in draw(self, renderer)
 836 def draw(self, renderer):
 837 self.update_coords(renderer)
--> 838 Text.draw(self, renderer)
 839 if self.get_dashlength() > 0.0:
 840 self.dashline.draw(renderer)

/usr/lib/python2.5/site-packages/matplotlib/text.py in draw(self, renderer)
 348
 349 renderer.draw_tex(gc, x, y, line,
--> 350   self._fontproperties, angle)
 351 return
 352

/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py in 
draw_tex(self, gc, x, y, s, prop, angle, ismath)
 379
 380 def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
--> 381 raise NotImplementedError
 382
 383 def draw_text(self, gc, x, y, s, prop, angle, ismath=False):

:

In [4]:

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib, usetex

2007-05-26 Thread Bill Jackson
Alexander Schmolck wrote the following on 05/25/2007 02:33 PM:
> I have no idea whether this will resolve your problem, but you could try
> updating to 0.90 (BTW what happens if you do axis([0,128,0,128])).

The problem appears to be with a matplotlibrc file.  If I delete the 
matplotlibrc file, then I am able to plot perfectly.  Thus, it appears 
that I am unable to specify usetex from my configuration file.  Why is 
this happening?

 ~/.matplotlib/matplotlibrc 
text.usetex : True

 test.py 
import matplotlib
import pylab
matplotlib.rc('text', usetex=True)
pylab.plot(range(10))
pylab.show()


Running 'python test.py' with the above matplotlibrc causes the errors 
in my original post.  Deleting matplotlibrc resolves the problem.





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Indentation for code readability

2007-03-30 Thread Mark Jackson
"DE" <[EMAIL PROTECTED]> writes:
> Hello,
> 
> Here is what I do in C++ and can not right now in python :
> 
> pushMatrix()
> {
>  drawStuff();
> 
>  pushMatrix();
>  {
> drawSomeOtherStuff()
>  }
>  popMatrix();
> }
> popMatrix();
> 
> The curly brackets have no functional meaning but increase the
> readability significantly.

You are e. e. cummings, and I claim my £5.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Every 10 years we say to ourselves, "If only we had
done the right thing 10 years ago."
- Thomas Friedman


-- 
http://mail.python.org/mailman/listinfo/python-list

Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-02-07 Thread Ron Jackson
I am using Python 2.5 on Windows XP. I have installed Pyserial and
win32all extensions.

When I try to run the example program scan.py (included below), or any 
other program using pyserial, as soon as it hits the statement:

s = serial.Serial(i)

I get the error:

Traceback (most recent call last):
   File "C:\Python25\Doc\PySerial Examples\scan.py", line 26, in 
 for n,s in scan():
   File "C:\Python25\Doc\PySerial Examples\scan.py", line 17, in scan
 s = serial.Serial(i)
   File "C:\Python25\Lib\site-packages\serial\serialutil.py", line 156,
in __init__
 self.open()
   File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 57,
in open
 win32file.SetupComm(self.hComPort, 4096, 4096)
error: (1, 'SetupComm', 'Incorrect function.')

What do I need to do to fix this? Thanks for the help!

   -- Ron


The example program scan.py (from the pyserial examples folder):
---
#!/usr/bin/env python
"""Scan for serial ports.
Part of pySerial (http://pyserial.sf.net)  (C)2002-2003 <[EMAIL PROTECTED]>

The scan function of this module tries to open each port number
from 0 to 255 and it builds a list of those ports where this was
successful.
"""

import serial

def scan():
 """scan for available ports. return a list of tuples (num, name)"""
 available = []
 for i in range(256):
 try:
 s = serial.Serial(i)
 available.append( (i, s.portstr))
 s.close()   #explicit close 'cause of delayed GC in java
 except serial.SerialException:
 pass
 return available

if __name__=='__main__':
 print "Found ports:"
 for n,s in scan():
 print "(%d) %s" % (n,s)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-02-08 Thread Ron Jackson
Dennis Lee Bieber wrote:
> On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
> 
> 
>>I am using Python 2.5 on Windows XP. I have installed Pyserial and
>>win32all extensions.
>>
> 
>   2.4 on XP Pro SP2...
> 
> 
>>When I try to run the example program scan.py (included below), or any 
>>other program using pyserial, as soon as it hits the statement:
>>
>>s = serial.Serial(i)
>>
> 
> 
>>>>import serial
>>>>for i in range(256):
> 
> ...   try:
> ...   print i,
> ...   s = serial.Serial(i)
> ...   print s.portstr
> ...   s.close()
> ...   except serial.SerialException:
> ...   print
> ...   
> 0 COM1
> 1
> 2 COM3
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> and on and on...
> 
> 
>>What do I need to do to fix this? Thanks for the help!
> 
> 
>   Does the serial port module require a compile for use with 2.5?
> Well, with only one download since Python 2.2, guess not...
> 
>   Something glitched in win32? Sorry, I don't know... However, since
> those are Python source files, you could always plug in some debugging
> lines around that win32 call to see what actually is there. Do you have
> any unnatural serial ports on the machine? (Like a USB<>serial
> converter?)

Trying your program, I get the same error 'Incorrect function.':

Traceback (most recent call last):
   File "", line 4, in 
 s = serial.Serial(i)
   File "C:\Python25\Lib\site-packages\serial\serialutil.py", line 156, in 
__init__
 self.open()
   File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 57, in open
 win32file.SetupComm(self.hComPort, 4096, 4096)
error: (1, 'SetupComm', 'Incorrect function.')


I tried PySerial on a laptop, also running XP Home SP2, and both the example 
program and the program you suggested work fine on the laptop.

The desktop computer that is giving me the error doesn't have any unnatural 
serial ports on it currently. The laptop worked fine, either with a USB device 
emulating COMM6 present or with the USB device disconnected.

I checked and both machines are running the same version of win32file, which is 
site-packages\win32\win32file.pyd, 88 KB dated 9/22/2006.

So my question is:

Why would the statement win32file.SetupComm(self.hComPort, 4096, 4096)

work just fine on one machine and not the other?

win32file.pyd can't be opened like a .py file, and I don't know what the rather 
cryptic error 'Incorrect function.' is trying to tell me. Does anyone who is 
familiar with win32file have an idea what the problem is?

Thanks for the help!

   -- Ron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv iterator question

2008-05-24 Thread David Jackson
Thanks, Ethan. that was a great solution. i just tested it.


On Fri, May 23, 2008 at 7:08 PM, Ethan Furman <[EMAIL PROTECTED]> wrote:

> davidj411 wrote:
>
>  When you save an open file to a variable, you can re-use that variable
>> for membership checking.
>> it does not seem to be that way with the csv.reader function, even
>> when set to a variable name.
>>
>> what is the best way to store the open CSV file in memory or do i need
>> to open the file each time?
>>
>> example of open method on file object:
>> fhandle=open(filename).readelines()
>>
>>
> >>> fhandle = open('c:/temp/08-02024.csv').readlines()
> >>> type(fhandle)
> 
> >>> len(fhandle)
> 381
>
> fhandle is a list containing the contents of the file, not a file handle --
> that's why you can easily re-use it.
>
>  example of csv.reader method:
>> reader = csv.reader(open(csvfilename))
>>
>>
> Try this instead:
> >>>reader  = csv.reader(open('c:/temp/08-02024.csv'))
> >>> contents = [line for line in reader]
> >>> type(contents)
> 
> >>> len(contents)
> 381
>
> You still get a list that you can easily use, that has gone through the csv
> routines.
>
> Hope this helps.
> --
> Ethan
>
>
--
http://mail.python.org/mailman/listinfo/python-list

I love "shelf" BUT

2008-07-27 Thread Sera Jackson
ok, I know its an over discussed topic. Althought I understand why it
is there I cant constantly see it in my argument list in parenthesis.

can someone give me an insight of the cons of a syntax like this:
class Class:
def self.method(arguments):
etc, etc


In other words def method(self, arg1, arg2 ,argN) becomes->  def
self.method(arg1, arg2 ,argN)

--
http://mail.python.org/mailman/listinfo/python-list


Re: I love "shelf" BUT

2008-07-27 Thread Sera Jackson
On Jul 28, 6:25 am, alex23 <[EMAIL PROTECTED]> wrote:
> On Jul 28, 12:46 pm, Sera Jackson <[EMAIL PROTECTED]> wrote:
>
> > ok, I know its an over discussed topic. Althought I understand why it
> > is there I cant constantly see it in my argument list in parenthesis.
>
> > can someone give me an insight of the cons of a syntax like this:
> > class Class:
> >     def self.method(arguments):
> >         etc, etc
>
> > In other words def method(self, arg1, arg2 ,argN) becomes->  def
> > self.method(arg1, arg2 ,argN)
>
> Did you bother to check the group? You would've noticed it's being
> discussed -right 
> now-:http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5f...
>
> And this -exact- suggestion has been turned down by 
> Guido:http://mail.python.org/pipermail/python-3000/2006-April/000793.html

alex thank you very much!

I searched excessively python mailing list but unforurtunately I was
using  as query and I missed
it, although I knew it should had been there. I mostly found threads
insisting on a complete removal...

And I sincerely apologise for missing the discussion here, I was tired
digging python old mailing list. :D.

Lot of thanks again, that's what I wanted to find, arguments against
it, I was aware I wan not speaking of sth new.
--
http://mail.python.org/mailman/listinfo/python-list


automatic from module import * expansion

2006-03-13 Thread Keith Jackson
Does anybody know of a tool that will take a module as input, look for 
any wildcard imports, and then identify what symbols in the module come 
from which wildcard import? It could then expand out the from module 
import * to from module import foo, bar. It might need to ask the user 
on this, since they might want the wildcard import for something 
special, but it would still be *much* nicer then expanding the imports 
out by hand.

Apologies ahead of time if I've missed something obvious. I did spend 
some quality time with google, and couldn't find anything.
cheers,
--keith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Characters contain themselves?

2006-04-07 Thread Mark Jackson
Rene Pijlman <[EMAIL PROTECTED]> writes:
> WENDUM Denis 47.76.11 (agent):
> >While testing recursive algoritms dealing with generic lists I stumbled 
> >on infinite loops which were triggered by the fact that (at least for my 
> >version of Pyton) characters contain themselves.
> 
> No, strings contain characters. And 'a' is a string consisting of one
> character.
> 
> "The items of a string are characters. There is no separate character
> type; a character is represented by a string of one item."
> http://docs.python.org/ref/types.html
> 
> (One item of what type, one might ask)

Good point.  ". . .represented by a string of length one" would be
better.


-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
An information system based on theory isolated from reality
is bound to fail.   - Mitch Kabay


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI remote call in python script to create process on remote windows computer

2009-10-07 Thread David Jackson
ok, cut and pasted, but changed the username/password to protect the innocent.
this is from interactive prompt.
let me know if i am still not doing the slashes correctly please.
i doubt authentication is the issue.; i can get pid information using
WQL queries.
objCreateProc.Create expects 4 strings (not objects?), right?

version info:
>>> sys.version
'2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)]'

>>> import win32com.client
>>> computer = "servername"
>>> strUser = "servername\\my_account"
>>> strPassword ="shh_secret"
>>> objSWbemLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
>>> objSWbemServices = objSWbemLocator.ConnectServer(computer, 
>>> r"root\cimv2",strUser,strPassword)
>>> objCreateProc = objSWbemServices.Get("Win32_Process")
>>> ProcessID  = u"200"
>>> objCreateProc.Create(u"cmd /c ping 127.0.0.1 
>>> >>c:\\temp\\finall.log",u"c:\\temp",u' ',ProcessID )
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not callable


how can i see the method available?
>>> help(objCreateProc) just gives me "Help on instance of CDispatch in module 
>>> win32com.client:"

Thanks
David
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Russell Jackson
Hi,
I have the following code that works fine in Python 2.x, but I can't seem to
get it to work in Python 3 with Popen. Can you please tell me how to get the
same functionality out of Python 3? The gist of what I doing is in the
setpassword function. I have tried numerous ways to get this to work, and
just can't figure it out, and the docs on Popen are no help whatsoever on
how to use the now open process. The examples completely skip over what to
do with the process after you open it.

The command I am running is a Perforce "p4 passwd username" command. It
prompts for the password twice, and I have to enter it twice to reset a
user's password. I would appreciate your help on getting this to work under
Python 3.

Rusty


Working code in Python 2.x (Does not work in Python 3.)

import os
import string
import sys
import time


###
def setpassword(user):
password = "passworD\n"

p4passwd = os.popen( "p4 passwd %s" % user, 'w' )
time.sleep(1)
 p4passwd.write( password )
time.sleep(1)
p4passwd.write( password )

if p4passwd.close() == 1:
print "Password reset failed.\n"
 sys.exit( 1 )

###
if __name__ == '__main__':
 if len (sys.argv) <= 1:
print "Read the usage section at the top of the script for required
parameters."
 sys.exit(1)

user = sys.argv[1]

setpassword(user)





Attempted code in Python 3: (Doesn't work either)



import os
import string
import sys
import time
import platform
from subprocess import *

if platform.system() == "Windows":
p4="p4.exe"
else:
p4="/p4/1/bin/p4_1"

###
def log(msglevel="DEBUG", message=""):
if msglevel == "TEST":
print("Running in test mode. Command run would have been:\n",
message)
elif msglevel == "ERROR":
print(message)
sys.exit(1)
elif (verbosity == "3"):
print(message)
elif (verbosity == "2" and msglevel == "INFO"):
print(message)

###
def setpassword(user):
password = "passworD\n"
try:
cmd = ' passwd {0}'.format(user)
pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
stderr=PIPE, universal_newlines=True)
stderr = pipe.stdin.write(password)
time.sleep(1)
stderr = pipe.stdin.write(password)
if pipe.stdin.close != 0:
log("ERROR", "Password reset failed.\n{0}{1} generated the
following error: {2}".format(p4, cmd, stderr))
except OSError as err:
log("ERROR", "Execution failed: {0}".format(err))

###
if __name__ == '__main__':
 if len (sys.argv) <= 1:
print ("Read the usage section at the top of the script for required
parameters.")
 sys.exit(1)

user = sys.argv[1]

setpassword(user)




-- 
Rusty

775-636-7402 Office
775-851-1982 Fax



-- 
Rusty

775-636-7402 Office
775-851-1982 Fax
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Russell Jackson
I just get an errorlevel from the executable when I read stdout, but I can't
tell what is going on because, of course, I can't tell what Popen is
actually doing. I never see the prompt from the executable that I would
expect to see when I read stdout.
I originally had the function like this:

def setpassword(user):
password = "passworD\n"
try:
cmd = ' passwd {0}'.format(user)
pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
stderr=PIPE, universal_newlines=True)
stdout = pipe.stdout.readline()
stderr = pipe.stdin.write(password)
time.sleep(1)
stdout = pipe.stdout.readline()
stderr = pipe.stdin.write(password)
if pipe.stdin.close != 0:
log("ERROR", "Password reset failed.\n{0}{1} generated the
following error: {2}".format(p4, cmd, stderr))
except OSError as err:
log("ERROR", "Execution failed: {0}".format(err))

but, the script just hung when I did that. I think it was stuck on the
readline, and never got anything from the process.

I didn't think that the if statement was incorrect based on examples I saw
in the docs, and the fact that it didn't complain about that part, but I'll
try the close():

Thanks,
Rusty



On Tue, Sep 15, 2009 at 4:24 PM, Rhodri James
wrote:

> On Wed, 16 Sep 2009 00:01:17 +0100, Russell Jackson <
> ru...@rcjacksonconsulting.com> wrote:
>
>  Hi,
>> I have the following code that works fine in Python 2.x, but I can't seem
>> to
>> get it to work in Python 3 with Popen. Can you please tell me how to get
>> the
>> same functionality out of Python 3? The gist of what I doing is in the
>> setpassword function. I have tried numerous ways to get this to work, and
>> just can't figure it out, and the docs on Popen are no help whatsoever on
>> how to use the now open process. The examples completely skip over what to
>> do with the process after you open it.
>>
>
> So how did it fail?
>
> ###
>> def setpassword(user):
>>password = "passworD\n"
>>try:
>>cmd = ' passwd {0}'.format(user)
>>pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
>> stderr=PIPE, universal_newlines=True)
>>stderr = pipe.stdin.write(password)
>>time.sleep(1)
>>stderr = pipe.stdin.write(password)
>>if pipe.stdin.close != 0:
>>
>
> Did you perhaps mean "if pipe.stdin.close():" ?
> Does it help if you read stdout rather than sleeping for arbitrary periods?
>
> --
> Rhodri James *-* Wildebeest Herder to the Masses
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Rusty

775-636-7402 Office
775-851-1982 Fax
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Russell Jackson
Yes, I don't think the problem is that isn't running the command, I think it
is just that I don't know how to communicate with it in the way that I need
to in order to make this work. I have tried finding examples of working with
Popen, but they are few and far between. I am not sure what was wrong with
os.popen that they felt it needed to be thrown away, but it certainly was
MUCH easier to work with than subprocess.Popen.
I even see examples of code where people are using the communicate call, and
passing in strings, but don't have universal_newline set to true. I can't
get that to work at all without the universal_newline being set to True. The
docs on the subprocess module need a lot of enhancement in my opinion given
that is is supposed to be the replacement for all the os.popen stuff in the
prior versions.

Thanks,
Rusty

On Tue, Sep 15, 2009 at 5:11 PM, Chris Rebert  wrote:

> On Tue, Sep 15, 2009 at 5:07 PM, Chris Rebert  wrote:
> > On Tue, Sep 15, 2009 at 4:01 PM, Russell Jackson
> >  wrote:
> > 
> >> Attempted code in Python 3: (Doesn't work either)
> > 
> >> cmd = ' passwd {0}'.format(user)
> >> pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
> >> stderr=PIPE, universal_newlines=True)
> 
>
> Scratch that, I neglected to notice the shell=True option.
>
> Cheers,
> Chris
>



-- 
Rusty

775-636-7402 Office
775-851-1982 Fax
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Russell Jackson
I received a reply from the help group that suggested I added a call to
flush in there, and that fixed it. The working code looks like this:
def setpassword(user):
password = "passworD\n"
try:
cmd = ' passwd {0}'.format(user)
pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
stderr=PIPE, universal_newlines=True)
stderr = pipe.stdin.write(password)
pipe.stdin.flush()
time.sleep(2)
stderr = pipe.stdin.write(password)
pipe.stdin.flush()
pipe.stdin.close()
if pipe.wait() != 0:
log("ERROR", "Password reset failed.\n{0}{1} generated the
following error: {2}".format(p4, cmd, stderr))
except OSError as err:
log("ERROR", "Execution failed: {0}".format(err))

Thanks,
Rusty


On Tue, Sep 15, 2009 at 6:37 PM, Chris Rebert  wrote:

> On Tue, Sep 15, 2009 at 4:58 PM, Russell Jackson
>  wrote:
> > I just get an errorlevel from the executable when I read stdout, but I
> can't
> > tell what is going on because, of course, I can't tell what Popen is
> > actually doing. I never see the prompt from the executable that I would
> > expect to see when I read stdout.
> > I originally had the function like this:
> > def setpassword(user):
> > password = "passworD\n"
> > try:
> > cmd = ' passwd {0}'.format(user)
> > pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
> > stderr=PIPE, universal_newlines=True)
> > stdout = pipe.stdout.readline()
> > stderr = pipe.stdin.write(password)
> > time.sleep(1)
> > stdout = pipe.stdout.readline()
> > stderr = pipe.stdin.write(password)
> > if pipe.stdin.close != 0:
> > log("ERROR", "Password reset failed.\n{0}{1} generated the
> > following error: {2}".format(p4, cmd, stderr))
> > except OSError as err:
> > log("ERROR", "Execution failed: {0}".format(err))
> > but, the script just hung when I did that. I think it was stuck on the
> > readline, and never got anything from the process.
> > I didn't think that the if statement was incorrect based on examples I
> saw
> > in the docs,
>
> I'm unable to locate any example in the subprocess docs using a
> similar "if". The closest is this code snippet:
>
> rc = pipe.close()
> if  rc != None and rc % 256:
>print "There were some errors"
>
> ...but that's used as an example of code *using os.popen()* in the
> context of how to translate it to use subprocess.Popen().
>
> > and the fact that it didn't complain about that part,
>
> Well, you're just comparing the .close method of a file object for
> equality with 0, which is valid, meaningful, and well-defined (hence,
> no error), but not useful or relevant in this context.
>
> >but I'll try the close():
>
> I agree with Rhodri that that "if" statement is definitely bunk.
> Rereading the docs, I think what was intended is:
>
> pipe.stdin.close()
> if pipe.wait() != 0:
>log(...)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>



-- 
Rusty

775-636-7402 Office
775-851-1982 Fax
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python-list Digest, Vol 57, Issue 206

2008-06-13 Thread STEVEN A JACKSON
Is there a Python programmer living near Bend Oregon that I could call via 
phone & ask some questions on how they accomplish certain tasks?  I’ve been 
programming using several languages for over fifty years, but am unable to get 
Python to due what I would like to do! Papa Jackson


From: [EMAIL PROTECTED]: Python-list Digest, Vol 57, Issue 206To: [EMAIL 
PROTECTED]: Fri, 13 Jun 2008 19:00:04 +0200Send Python-list mailing list 
submissions topython-list@python.org To subscribe or unsubscribe via 
the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-listor, via email, send a 
message with subject or body 'help' to [EMAIL PROTECTED] You can reach the 
person managing the list at [EMAIL PROTECTED] When replying, please edit your 
Subject line so it is more specificthan "Re: Contents of Python-list digest..."
--Forwarded Message Attachment--From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: 
Fri, 13 Jun 2008 21:59:06 +0530Subject: Python Socket programmingHi,I am going 
to do some socket related programming in Python. Before that, I wish to know 
the Gotchas of Python Scoket Programming.Can anyone send me any link that 
satisfies my needs??Thanks,SriniExplore your hobbies and interests. Go 
to http://in.promos.yahoo.com/groups/ 
--Forwarded Message Attachment--From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: 
[EMAIL PROTECTED]: Fri, 13 Jun 2008 10:28:45 -0600Subject: RE: namedtuple 
suggestionsI also agree with your point on concatting.  I used that syntax 
because itseemed more clear, given the already awkward syntax. And while the 
original motivation of namedtuple might be to avoid having tomake a class or 
subclass, subclasses have already emerged even within thestandard library (see 
lib/urlparse for a prime example of extending thenamedtuple class). 
Regards,Jason -Original Message-From: Calvin Spealman [mailto:[EMAIL 
PROTECTED] Sent: Friday, 13 June, 2008 12:17To: Jason R. CoombsCc: [EMAIL 
PROTECTED]: Re: namedtuple suggestions On Jun 13, 2008, at 11:17 AM, Jason R. 
Coombs wrote: > I see a new function in (python 2.6) lib/collections called> 
namedtuple.  This is a great function.  I can see many places in my> code where 
this will be immensely useful.>> I have a couple of suggestions.>> My first 
suggestion is to use self.__class__.__name__ instead of the> hard-coded 
typename in __repr__, so that subclasses don't have to> override these methods 
just to use the correct name.>> def __repr__(self):> return 
self.__class__.__name__ + '(%(reprtxt)s)' %% self> \n I feel like a large point 
of NamedTuple is for those cases where you  need a small object with some 
attributes _without_ creating a  subclass. Useful for mocks, for example, or 
when you need to trick a  function into dealing with a quick proxy or stub. If 
a large point is  not needing to create a class but instead creating a cheap 
object,  should it be a good idea to then subclass the very thing that was  
intended to help you avoid creating a class in the first place? What  do you 
gain subclassing it? However, I always think a repr reflecting a type name 
should reflect  the correct type, so I'm not disagreeing on that point. But, 
just  don't use concating :-)
--Forwarded Message Attachment--From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: 
Fri, 13 Jun 2008 16:41:46 +Subject: Automatically restarting system calls? 
I wrote a script(1) replacement in python 
(http://stromberg.dnsalias.org/~dstromberg/pypty/), but I'm encountering a 
problem in it. I think I know the solution to the problem, but I'd've thought 
python was high level enough that this solution isn't required, so I wanted to 
inquire about it here. Specifically, the program has a signal handler for 
window size changes.  And if the window is resized during an os.write() (for 
example), I get a python exception about needing to restart the system call. In 
C, I know you're supposed to wrap your system calls with while loops until you 
don't get an ERESTART, but does one really need to wrap all of one's 
os.write()'s (for example) with such while loops in python? Thanks!  
--Forwarded Message Attachment--From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: 
Fri, 13 Jun 2008 18:46:46 +0200Subject: Re: Python Socket programmingHi, Le 
Friday 13 June 2008 18:29:06 srinivasan srinivas, vous avez écrit :> Hi,> I am 
going to do some socket related programming in Python. Before that, I> wish to 
know the Gotchas of Python Scoket Programming. Can anyone send me> any link 
that satisfies my needs?? Yes, the friendly manual :) 
http://docs.python.org/lib/module-socket.html and if you want to know more 
about socket themselves, the gnu libc info page is a good starting point as the 
python module is basically an interface to it: 
http://www.gnu.org/software/libc/manual/html_node/Sockets.html#Sock

Any tips on Python web development on Mac OS

2008-08-05 Thread Tim Greening-Jackson

Hi there.

I've recently learned Python -- but would by no means describe myself as 
expert -- and have a couple of "pet" projects I want to do in my spare 
time in order to consolidate what I've learned by using it to solve 
"real" problems.


I'd like to create a couple of websites on my Mac at home. I have a very 
basic understanding of HTML, but am lazy and would prefer to do the work 
either in Python itself or have some package I can use in conjunction 
with Python.


So I need some sort of tool which can help me design the "look and feel" 
of the website, together with something that will help me generate the 
content. So I can produce the template for the pages (i.e. put this 
button/text here, and on rollover it changes colour and on click it goes 
to...) and also do "smart" things like take user feedback etc. etc.


I've had a very quick look at the Django and Turbogears websites. Is it 
worth learning one of these for a small, simple site? Will they actually 
help me set up the structure of the site, or are they more geared to its 
content.


I've also seen an open-source package for the Mac called Locomotive, but 
this appears to be a framework for Ruby on Rails and I don't want to 
learn Ruby.


I'm also trying to find/download HTMLgen. If I try to install the 
version from macports it tries to downgrade my installation of Python to 
one of the previous versions. Is it worth using and where can I find a 
copy that I should be able to build/install cleanly on a Mac.


I'm running:

Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin

on an elderly iMac G5 which runs Mac OS X 10.5.4 (9E17)

Any tips, pointers etc. would be gratefully received.

T.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hobbyist - Python vs. other languages

2008-08-05 Thread Tim Greening-Jackson

Tobiah wrote:


You may enjoy:

http://www.pythonchallenge.com/

It's a blast and a half.  To solve the
puzzles you have to write python programs
that do various things. 


Thanks for that. I can see that will keep me amused for quote some time.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any tips on Python web development on Mac OS

2008-08-05 Thread Tim Greening-Jackson

Bruno Desthuilliers wrote:

Tim Greening-Jackson a écrit :
(snip)
You're not going to get anywhere without learning (x)html and css IMHO. 
Even using a "graphical" html editor like Dreamweaver requires having a 
good enough (IOW : being able to do it all by hand) knowledge of these 
languages.


Well, to be honest I do know rudimentary HTML and have been playing with 
CSS by hand --- the only HTML editor I have is a public domain one 
called Taco. I can put together the basic template for the website, and 
use CSS to keep tuning the look and feel until it was right.


I have Apache/MySQL already running on my Mac, a fairly fast broadband 
connection with a static IP address and a vanity domain to point at the 
server. So I could serve it all from home.



Depends on what your "site" is doing.


There are all *sorts* of things I would like it to do, but am not 
dogmatic about any of them. For example, having various people being 
able to login to it securely to shuttle files between ourselves would be 
useful. As would webmail access. And various "robot" functionality...


The exercise is more to see what Python can do to help me develop 
websites and get used to some sort of proper development framework, 
rather than Apple iWeb which is superficially attractive but 
fundamentally crippled and produces unreadable HTML.


There are quite a couple other (and more recent) "html generator" 
packages. You may want to have a look at brevé:

http://breve.twisty-industries.com/


Thanks. I'll take a look.
--
http://mail.python.org/mailman/listinfo/python-list


Python lunch and file accessing challenges

2021-01-30 Thread jackson kwame via Python-list
 Hi

I'm new to Python and currently taking part in a Data Science course. Python is 
the main coding/programming language for the course. We were guided to download 
the Python application through Anaconda which worked. I have been using 
Jupyther through a browser to practice Python exercises. However anytime we are 
given an assignment in Python and I download, it doesn't open in Python. 


How can I lunch Python on my PC and secondly how can I open Python files on my 
PC.  


Thank you.


David
-- 
https://mail.python.org/mailman/listinfo/python-list