I need some advice/help on running my scripts

2005-01-01 Thread Sean
For the last couple of months I have been reading and working throught
the examples in Magnus Lie Hetland's Book "Practical Python"  This for
all practical purposes is the first computer programming language I
have spent any time at learning, so much of what I have covered in the
book was for the first time.

My problem is that many of the example scripts are run on Linux
machines and I am using Win XP Pro.  Here is a specific example of what
is confusing me.  If I want to open a file from the dos prompt in some
script do I just write the name of the file I want to open (assuming it
is in the same directory) after the script name?
such as

c:\some_script.py some_text_file.txt

Does piping work the same way in dos as it does on a linux machine?
And last but not least, is there a way to do this all from IDLE?

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


? about file() and open()

2005-01-02 Thread Sean
Was wondering if there was any difference between these two functions.
I have read some text that said file() wasn't introduced until 2.2 and
that it was synonymous with open().  Does this mean that I should be
using file() where I used open() before?

Sean Morris

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


Re: list item's position

2005-01-19 Thread Sean
Not sure if this is what you are looking for but...

>>> li = ['this','is','a','list','of','strings']
>>> li = [l for l in li if li.index(l) >= li.index('a')]
>>> li
['a', 'list', 'of', 'strings']
>>>



-- 
Sean Berry ~ Internet Systems Programmer
BuildingOnline Inc.
The Building Industry's Web Design and Marketing Agency
Celebrating our 9th year in business, founded Aug. 1995
Ph: 888-496-6648 ~ Fax: 949-496-0036
  --> Web Design Agency site: http://www.BuildingOnline.net
  --> Building Industry Portal: http://www.BuildingOnline.com
  --> Building Industry News: http://www.BuildingOnline.com/news/
  --> Home Plans: http://www.eHomePlans.com
"Bob Smith" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> I have a Python list. I can't figure out how to find an element's numeric 
> value (0,1,2,3...) in the list. Here's an example of what I'm doing:
>
> for bar in bars:
>if 'str_1' in bar and 'str_2' in bar:
>   print bar
>
> This finds the right bar, but not its list position. The reason I need to 
> find its value is so I can remove every element in the list before it so 
> that the bar I found somewhere in the list becomes element 0... does that 
> make sense?
>
> Thanks,
>
> Bob 


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


Calling a function from module question.

2005-02-15 Thread Sean
Is there any way I could have the following work?

First I would have a module define a function to do
something like print some data.

- module_name.py -

[snip]

def print_this(data):
print "This is the data: %s" %data

[/snip]

-


Then I would have a script that uses the
print_this function defined in the module
without using the module name in the call.

- test_file.py -

[snip]

import module_name.py
print_this("lots of data")

[/snip]

--

Now, I know I can call the function using
module_name.print_this("lots of data")
but can using the module name at the beginning
be avoided?

If not, why?  I am sure there is a good pythonic
explanation.

Thanks 


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


Re: Calling a function from module question.

2005-02-15 Thread Sean
> Sean wrote:
>
>> Then I would have a script that uses the
>> print_this function defined in the module
>> without using the module name in the call.
>
>
>
> from module_name import print_this
>
> or, even:
>
> from module_name import print_this as other_nice_name
>

So what if I have a whole bunch of functions - say 25 of them.
Is there a way to do this without naming each function?


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


Re: Calling a function from module question.

2005-02-15 Thread Sean
>>>from module_name import print_this
>>>
>>>or, even:
>>>
>>>from module_name import print_this as other_nice_name
>>
>> So what if I have a whole bunch of functions - say 25 of them.
>> Is there a way to do this without naming each function?
>
> Yes [1], but it's basically deprecated and you shouldn't use it. Consider 
> refactoring your code.
>

Refactoring my code?  Sorry, I am not sure what you mean here.

How would one refactor the example in my original post? 


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


Re: Rookie Question: Passing a nested list into a function?

2005-04-14 Thread Sean
Brett,

Hard to tell exactly what you're trying to do here, but it looks like
you'd be better served using one of the built in python data
structures.

For example: If you're trying to compare some elements of these
textfiles that are broken into titles, and contents for each file, try
something like:

myfiles = [ 'test.txt', 'test1.txt', 'test2.txt', 'test3.txt',
'test4.txt' ]
myfiledict = {}

for filename in myfiles:
openfile = file(filename)
myfiledict[filename] = [ line.strip() for line in
openfile.readlines()]
openfile.close()
# easier to read this way
# self.content = []
# for line in f.readlines():
# self.content.append(line.strip())


# then the contents of the file "test.txt" are accessable with the
expression:
# myfiledict['test.txt']

# if you make a few lists of files, then you can compare them like this

for k1, k2 in myfiledict, cmpfiledict:
# if list == titlelist2[y][1]: From your code. The line below is
what
# I think you want.
if k1 == k2:
# Whatever happens in your code that you've clipped.

If you post the rest of your code, or email me, then I'll be happy to
answer your question.

-S

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


python's library support

2006-02-03 Thread Sean
I am a newbie in python, and I have a feeling that python provides less
library support than perl www.cpan.org  This seems a big discussion
topic.

I want to know if there is extensive algorithm library support in
python. I know there is a pretty neat module in perl to implement graph
theory. Is there a graph theory module in python?

Thanks,

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


help reading cookie values

2007-07-13 Thread Sean
I am trying to read a cookie I set but I am not sure if I really set
it correctly or I am not reading it correctly.  I was given the
following instructions to set the cookie.  It appears to be working
because in Firefox browser I see the cookie listed for my domain

> you set a cookie in a pythonscript like:
> context.REQUEST.RESPONSE.setCookie('cookie_name', 'some value',
> expires=(DateTime() + 365).toZone('GMT').rfc822(), path='/')
>

 I have been searching everywhere to find information on reading the
cookie value that I set.  I used the following code I found which
returns 'no cookiez' in spite of the fact that I see the cookie in my
browser's cookie listing.  I must be doing something wrong in the way
I am testing for its existence

import Cookie
import os
thiscookie = Cookie.SimpleCookie()

if 'HTTP_COOKIE' in os.environ:
#if os.environ.has_key('HTTP_COOKIE'): I tried this way also

thiscookie.load(os.environ['HTTP_COOKIE'])

a_code = thiscookie['my_cookie'].value

return a_code

else:

return 'no cookiez'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python dictionary size/entry limit?

2009-02-21 Thread Sean

Stefan Behnel wrote:

intellimi...@gmail.com wrote:
You may be better served with one of the dbm databases that come with
Python. They live on-disk but do the usual in-memory caching. They'll
likely perform a lot better than your OS level swap file.

Stefan


the bsddb module has the feature that access to the database uses the 
same methods as python dictionaries.


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


3.0 - bsddb removed

2009-03-22 Thread Sean
Anyone got any thoughts about what to use as a replacement.  I need 
something (like bsddb) which uses dictionary syntax to read and write an 
underlying (fast!) btree or similar.


Thanks.

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


Re: very large dictionary

2008-08-01 Thread Sean

Simon Strobl wrote:

Hello,

I tried to load a 6.8G large dictionary on a server that has 128G of
memory. I got a memory error. I used Python 2.5.2. How can I load my
data?

SImon


Take a look at the python bsddb module.  Uing btree tables is fast, and 
it has the benefit that once the table is open, the programing interface 
is identical to a normal dictionary.


http://docs.python.org/lib/bsddb-objects.html

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


Python Web App

2010-12-22 Thread Sean
Anybody know where I can find a Python Development Environment in the
form of a web app for use with Chrome OS. I have been looking for a
few days and all i have been able to find is some old discussions with
python developers talking about they will want one for the OS to be a
success with them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Sean
I am wanting to learn python and I am test a Chrome OS notebook at the
same time so I need something that will atleast tell me if I have any
syntax errors. Although the more features the better that way learning
is an easier experience.

On Dec 22, 7:05 pm, Hidura  wrote:
> I am creating one, is on test, what kind of app do you want create?
>
> 2010/12/22, Sean :
>
> > Anybody know where I can find a Python Development Environment in the
> > form of a web app for use with Chrome OS. I have been looking for a
> > few days and all i have been able to find is some old discussions with
> > python developers talking about they will want one for the OS to be a
> > success with them.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
> Enviado desde mi dispositivo móvil
>
> Diego I. Hidalgo D.

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


Re: Python Web App

2010-12-22 Thread Sean
Forgot to point out that Chrome OS has no local storage accessable to
the user. Hence why I need a web based solution.

On Dec 22, 8:51 pm, Sean  wrote:
> I am wanting to learn python and I am test a Chrome OS notebook at the
> same time so I need something that will atleast tell me if I have any
> syntax errors. Although the more features the better that way learning
> is an easier experience.
>
> On Dec 22, 7:05 pm, Hidura  wrote:
>
>
>
>
>
>
>
> > I am creating one, is on test, what kind of app do you want create?
>
> > 2010/12/22, Sean :
>
> > > Anybody know where I can find a Python Development Environment in the
> > > form of a web app for use with Chrome OS. I have been looking for a
> > > few days and all i have been able to find is some old discussions with
> > > python developers talking about they will want one for the OS to be a
> > > success with them.
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > --
> > Enviado desde mi dispositivo móvil
>
> > Diego I. Hidalgo D.

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


Re: Python Web App

2010-12-26 Thread Sean
@Katie
Thank you I considered this option until I realized it wouldn't let me
do anything other than ping from the command line.

The rest of you all make valid points after doing a little more
research on my own I found some really nice web based text editors but
they didn't have any testing abilities which meant learning in that
environment wasn't feasible in my opinion. I am inclined to agree that
chrome OS will probably not do as well as they want it to but with the
kind of capital Google has they could easily flood the market. In the
end I wound up giving the notebook to my mom because all she really
does is check her email and Facebook so it was perfect for her.

Thank You for all the responses they were a great help with me testing
the notebook.

On Dec 25, 9:02 pm, Katie T  wrote:
> On Wed, Dec 22, 2010 at 9:43 PM, Sean  wrote:
> > Anybody know where I can find a Python Development Environment in the
> > form of a web app for use with Chrome OS. I have been looking for a
> > few days and all i have been able to find is some old discussions with
> > python developers talking about they will want one for the OS to be a
> > success with them.
>
> Your best bet is probably just to SSH to a *nix box and use something
> like vim or emacs. None of the web solutions are anywhere near acceptable.
>
> Katie
> --
> CoderStackhttp://www.coderstack.co.uk/python-jobs
> The Software Developer Job Board

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


Best way to add a "position" value to each item in a list

2009-07-09 Thread Sean
I have a huge list, 10,000,000+ items.  Each item is a dictionary with
fields used to sort the list.  When I have completed sorting I want to
grab a page of items, say 1,000 of them which I do easily by using
list_data[x:x+1000]

Now I want to add an additional key/value pair to each dictionary in
the list, incrementing them by 1 each time.  So, if I grabbed page 2
of the list I would get:

[{'a':'a', 'b':'b', 'position':1001}, {'c':'c', 'd':'d', 'position':
1002}, ...]

Any way to do that with list comprehension?  Any other good way to do
it besides iterating over the list?

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


Re: Best way to add a "position" value to each item in a list

2009-07-09 Thread Sean
On Jul 9, 1:16 pm, Sean  wrote:
> I have a huge list, 10,000,000+ items.  Each item is a dictionary with
> fields used to sort the list.  When I have completed sorting I want to
> grab a page of items, say 1,000 of them which I do easily by using
> list_data[x:x+1000]
>
> Now I want to add an additional key/value pair to each dictionary in
> the list, incrementing them by 1 each time.  So, if I grabbed page 2
> of the list I would get:
>
> [{'a':'a', 'b':'b', 'position':1001}, {'c':'c', 'd':'d', 'position':
> 1002}, ...]
>
> Any way to do that with list comprehension?  Any other good way to do
> it besides iterating over the list?
>
> Thanks

I was able to do this by doing the following:
page_data = [[start_position + 1 + n, x] for n, x in enumerate
(page_data)]

However, this creates a list of lists, each containing an int and a
dictionary.  I wanted to add it directly to the dictionary.  I can add
the key position to the dictionary when the data is created, but how
would I assign the value in a list comprehension?

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


Re: Best way to add a "position" value to each item in a list

2009-07-09 Thread Sean
On Jul 9, 1:16 pm, Sean  wrote:
> I have a huge list, 10,000,000+ items.  Each item is a dictionary with
> fields used to sort the list.  When I have completed sorting I want to
> grab a page of items, say 1,000 of them which I do easily by using
> list_data[x:x+1000]
>
> Now I want to add an additional key/value pair to each dictionary in
> the list, incrementing them by 1 each time.  So, if I grabbed page 2
> of the list I would get:
>
> [{'a':'a', 'b':'b', 'position':1001}, {'c':'c', 'd':'d', 'position':
> 1002}, ...]
>
> Any way to do that with list comprehension?  Any other good way to do
> it besides iterating over the list?
>
> Thanks

I was able to do this by doing the following:
page_data = [[start_position + 1 + n, x] for n, x in enumerate
(page_data)]

However, this creates a list of lists, each containing an int and a
dictionary.  I wanted to add it directly to the dictionary.  I can add
the key position to the dictionary when the data is created, but how
would I assign the value in a list comprehension?

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


Re: Timsort in Cpython

2013-06-19 Thread sean . westfall
On Sunday, June 16, 2013 1:16:02 PM UTC-7, Dennis Lee Bieber wrote:
> On Sun, 16 Jun 2013 09:15:11 -0700 (PDT), alphons...@gmail.com declaimed
> 
> the following:
> 
> 
> 
> >sorry about that. I'm new to google groups. I'm trying to make sense of 
> >python's implementation of timsort through cpython: 
> >http://hg.python.org/cpython/file/default/Objects/listobject.c
> 
> >
> 
>   Since you are new to GoogleGroups, if you can, run away from it as fast
> 
> as possible. While material may look okay on their system, it is
> 
> practically trashed when getting out into the real world. (Paragraphs
> 
> either come in as long lines with no wrapping [Usenet/Email convention is
> 
> for 80 character lines, and to allow for > quotes original text should wrap
> 
> around 72-75], or they end up double-spacing stuff that comes in following
> 
> the 80 character line length (GG is treating hard end-of-line as a
> 
> paragraph marker, and on quoting, adding a blank line between these
> 
> "paragraphs")
> 
> 
> 
>   Either subscribe to the mailing list (and use a real mail client rather
> 
> than web-mail) or use a news reader; if your ISP doesn't provide an NNTP
> 
> server carrying comp.lang.python, it is available from Gmane as
> 
> gmane.comp.python.general (the mailing list and comp.lang.python are cross
> 
> linked, and Gmane shows the mailing list as if it were a Usenet news group)
> 
> 
> 
>   And just another comment: preference on the group is "trim quoted
> 
> material and comment below the quote (or interspersed with the quotes)"...
> 
> The style created with M$ Outlook (Outlook goes out of its way to make it
> 
> impossible to trim/intersperse -- it considers quoted material as a
> 
> photocopy attached to the back of a new letter) in which one comments at
> 
> the top of the quoted material, and never trims to relevant material is
> 
> frowned upon.
> 

Understood. I just subscribed to the news group, though I'm using gmail. 
hopefully it will work better than google groups.

I'll keep all the advice here in mind whenever I post.

> -- 
> 
>   Wulfraed Dennis Lee Bieber AF6VN
> 
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

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


Re: Timsort in Cpython

2013-06-19 Thread sean . westfall
On Sunday, June 16, 2013 1:33:17 PM UTC-7, Ian wrote:
> On Sat, Jun 15, 2013 at 10:05 PM,   wrote:
> 
> > Yes I've read it. Very interesting read. There are other resources too 
> > online that make it very clear, for instance the wikipedia articles is 
> > pretty good.
> 
> >
> 
> > Though, if anyone would be interested in helping me out further -- though 
> > by all means, I'm not lazy, I can figure it myself. But, I wanted to pass 
> > in variables into listsort and watch timsort work line by line in gdb.
> 
> >
> 
> > listsort(PyListObject *self, PyObject *args, PyObject *kwds)
> 
> >
> 
> > I've never worked with Cpython source before, but it looks like PyObject is 
> > just some type of general strut.. I think anyway. How does python represent 
> > a list of ints in source? and what are the two second arguments for, 
> > assuming the first is the list strut.
> 
> 
> 
> A PyObject* generally references any Python object.  The subtype
> 
> PyListObject* more specifically references a Python list.  The above
> 
> signature corresponds to this Python function signature:
> 
> 
> 
> def listsort(self, *args, **kwds):
> 
> 
> 
> The first argument self is the list object to be operated on.  The
> 
> second argument args is a Python tuple containing any other positional
> 
> arguments that were passed into the method.  The third argument kwds
> 
> is a Python dict containing any keyword arguments that were passed
> 
> into the method.

The second argument takes the tuple which determines which varialble(key) to 
use the comparator on. And the third determines whether to return the list in 
ascending or descending order. But how do these PyObject* look in C?

How does a PyListObject* look declared in CPython. How would something like 
this list = [2, 1, 5, 6, 10] look in CPython. Or what about something more 
complicated -- mlist = [('A',1),('B',2),('C',3)].

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


Re: rmtree message

2017-09-13 Thread Sean DiZazzo
On Wednesday, September 13, 2017 at 12:06:20 PM UTC-7, larry@gmail.com 
wrote:
> I have a script that creates a tmp dir, create a lot of files in it,
> and when done, does a rmtree on the dir. When it does that I get this
> message:
> 
> shell-init: error retrieving current directory: getcwd: cannot access
> parent directories: No such file or directory
> 
> But no exception is thrown. How can I determine why I get this message?

I usually see that message when I am in a directory in the shell but it has 
already been deleted by another process.  

Make sure the directory exists.  Is another part of your script deleting the 
root directory while rmtree is running?  Or something of the like.

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


Re: Python dress

2017-09-13 Thread Sean DiZazzo
On Tuesday, September 12, 2017 at 9:18:12 AM UTC-7, larry@gmail.com wrote:
> Not too many females here, but anyway:
> 
> https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress
> 
> (And if any guys want to wear this, there's nothing wrong with that.)

I'm going to buy it for my girl wear it to all of my work parties.  :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python dress

2017-09-13 Thread Sean DiZazzo
On Wednesday, September 13, 2017 at 3:02:18 PM UTC-7, bream...@gmail.com wrote:
> On Wednesday, September 13, 2017 at 10:43:47 PM UTC+1, Sean DiZazzo wrote:
> > On Tuesday, September 12, 2017 at 9:18:12 AM UTC-7, larry@gmail.com 
> > wrote:
> > > Not too many females here, but anyway:
> > > 
> > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress
> > > 
> > > (And if any guys want to wear this, there's nothing wrong with that.)
> > 
> > I'm going to buy it for my girl wear it to all of my work parties.  :)
> 
> What is she going to wear? :)
> 
> --
> Kindest regards.
> 
> Mark Lawrence.

She's gonna wear the geek dress with pride!  She knows.

There's a nice little Coco Chanel I have picked out for myself.  :P
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A good way to unpack a matrix

2017-09-13 Thread Sean DiZazzo
On Wednesday, September 13, 2017 at 7:53:25 PM UTC-7, Andrew Zyman wrote:
> hello,
>  is there a better approach to populating a function in this situation?
> 
> res = self.DB.getPrice():  # returns array of 3x2 always.  symbol_id,
> symbol, price.
> 
> var1 = self.AFunction(symbols=res[0][2] + '.' + res[1][2], conid1=
> self.Contracts[res[0][0]].conId,
> 
> conid2=self.Contracts[res[1][0]].conId, price1= res[0][2], price2=
> res[1][2])
> 
> 
> Thank you.

OOP?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the core values of the Python "platform"

2017-09-13 Thread Sean DiZazzo
On Wednesday, September 13, 2017 at 6:16:58 AM UTC-7, leam hall wrote:
> On Wed, Sep 13, 2017 at 9:08 AM, Darin Gordon  wrote:
> 
> > Bryan Cantrill gave an interesting talk recently at a Node conference about
> > "platform values" [1]. The talk lead me to think about what the core values
> > of the Python "platform" are and I thought it would be good to ask this
> > question of the community. What would you consider the top (<= 5) core
> > values?
> >
> >
> Would that be close to the Zen of Python?

The Zen of Python says it all.

There might be some that argue with intricacies, but the core values are 
expressed clearly in it.  Some people just like to argue.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "tkinter"

2017-09-13 Thread Sean DiZazzo
On Wednesday, September 13, 2017 at 7:21:25 PM UTC-7, Grant Edwards wrote:
> On 2017-09-13, Ben Finney  wrote:
> 
> > The toolkit in question is named “tk”, which I have only ever known to
> > be pronounced “tee kay”.
> >
> > The rest of the word is an abbreviation of “interface”.
> >
> > So, to me “Tkinter” is pronounced “tee kay inter”.
> 
> Same here.  Though I've probably said it aloud less than a half-dozen
> times in the past twenty-whatever years.
> 
> --
> Grant

I usually just say "tinker", since it's easy...knowing that it's wrong.  I 
agree with the "tee-kay" folks on correct pronunciation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Create an alias to an attribute on superclass

2018-02-01 Thread Sean DiZazzo
Hi!

I basically just want to create an alias to an attribute on an item's 
superclass.  So that after I create the subclass object, I can access the alias 
attribute to get the value back.


class Superclass(object):
def __init__(self, value):
"""
I want to pass x by reference, so that any time
x on the subclass is updated, so is the alias here
"""
self.alias = value

class Subclass(Superclass):
def __init__(self, x):
self.x = x
Superclass.__init__(self, self.x)

def __repr__(self):
return "x: %s\nalias: %s" % (self.x, self.alias)


if __name__ == "__main__":
foo = Subclass(1)
print foo.alias

foo.x = 6
# Should return 6 !!!
print foo.alias


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


Re: Create an alias to an attribute on superclass

2018-02-01 Thread Sean DiZazzo
On Thursday, February 1, 2018 at 10:37:32 AM UTC-8, Chris Angelico wrote:
> On Fri, Feb 2, 2018 at 5:22 AM, Sean DiZazzo  wrote:
> > Hi!
> >
> > I basically just want to create an alias to an attribute on an item's 
> > superclass.  So that after I create the subclass object, I can access the 
> > alias attribute to get the value back.
> >
> > 
> > class Superclass(object):
> > def __init__(self, value):
> > """
> > I want to pass x by reference, so that any time
> > x on the subclass is updated, so is the alias here
> > """
> > self.alias = value
> >
> > class Subclass(Superclass):
> > def __init__(self, x):
> > self.x = x
> > Superclass.__init__(self, self.x)
> >
> > def __repr__(self):
> > return "x: %s\nalias: %s" % (self.x, self.alias)
> >
> >
> > if __name__ == "__main__":
> > foo = Subclass(1)
> > print foo.alias
> >
> > foo.x = 6
> > # Should return 6 !!!
> > print foo.alias
> >
> > 
> 
> ISTM the easiest way would be to define a property on the superclass:
> 
> class Superclass(object):
> @property
> def alias(self):
> return self.x
> 
> Whatever happens, self.alias will be identical to self.x. Is that what
> you're after?
> 
> ChrisA

Yes, but that doesn't seem to work.  It looks like there is a way to do it if 
you make the original value a list (mutable) instead of an integer.  I really 
need to do it with an arbitrary object.  Not sure if I can hack the list trick 
to work in my case though.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create an alias to an attribute on superclass

2018-02-01 Thread Sean DiZazzo
On Thursday, February 1, 2018 at 10:23:06 AM UTC-8, Sean DiZazzo wrote:
> Hi!
> 
> I basically just want to create an alias to an attribute on an item's 
> superclass.  So that after I create the subclass object, I can access the 
> alias attribute to get the value back.
> 
> 
> class Superclass(object):
> def __init__(self, value):
> """
> I want to pass x by reference, so that any time
> x on the subclass is updated, so is the alias here
> """
> self.alias = value
> 
> class Subclass(Superclass):
> def __init__(self, x):
> self.x = x
> Superclass.__init__(self, self.x)
> 
> def __repr__(self):
> return "x: %s\nalias: %s" % (self.x, self.alias)
> 
> 
> if __name__ == "__main__":
> foo = Subclass(1)
> print foo.alias
> 
> foo.x = 6
> # Should return 6 !!!
> print foo.alias
> 
> 

Yep.  Thats it.  Thank you guys!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a simple question

2021-07-29 Thread Sean DiZazzo
On Tuesday, July 27, 2021 at 5:05:27 AM UTC-7, Terry Reedy wrote:
> On 7/26/2021 6:19 PM, Glenn Wilson via Python-list wrote: 
> > I recently downloaded the latest version of python, 3.9.6. Everything works 
> > except, the turtle module. I get an error message every time , I use basic 
> > commands like forward, backward, right and left. My syntax is correct: 
> > pat.forward(100) is an example. Can you tell me what is wrong.
> On Windows, normal install, 
> C:\Users\Terry>py -3.9 -m turtle 
> C:\Users\Terry>py -3.9 -m turtledemo 
> both work. 
> 
> 
> -- 
> Terry Jan Reedy

Welcome to programming!!  Ain't it fun?!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Errno 2] No such file or directory:

2021-07-30 Thread Sean DiZazzo
On Thursday, July 29, 2021 at 7:42:58 AM UTC-7, joseph pareti wrote:
> indeed. There are better options than the one I attempted. Thanks for the 
> advice 
> 
> Am Mi., 28. Juli 2021 um 18:19 Uhr schrieb Chris Angelico  >:
> > On Thu, Jul 29, 2021 at 2:10 AM joseph pareti 
> > wrote: 
> > > 
> > > The following code fails as shown in the title: 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > *import subprocesscmd = 'ls -l 
> > > 
> > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> >  
> > > | awk "{print $9 }"'process = subprocess.Popen([cmd],
> > > stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = 
> > > process.communicate()print('stdout ',stdout)print('stderr ',stderr)* 
> > > 
> > >  
> > > 
> > > Traceback (most recent call last): 
> > > File "PreProcess_1a.py", line 3, in  
> > > process = subprocess.Popen([cmd], stdout=subprocess.PIPE, 
> > > stderr=subprocess.PIPE) 
> > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 
> > 854, 
> > > in __init__ 
> > > self._execute_child(args, executable, preexec_fn, close_fds, 
> > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 
> > > 1702, in _execute_child 
> > > raise child_exception_type(errno_num, err_msg, err_filename) 
> > > FileNotFoundError: [Errno 2] No such file or directory: 'ls -l 
> > > 
> > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> >  
> > > | awk "{print $9 
> > > 
> >
> > First off, you'll want to post code in a way that keeps the 
> > formatting, otherwise it becomes very hard to read. 
> > 
> > But the immediate problem here is that Popen takes an array of command 
> > arguments, NOT a shell command line. You cannot invoke ls and pipe it 
> > into awk this way. 
> > 
> > Don't think like a shell script. Python has very good 
> > directory-listing functionality, and you will very very seldom need to 
> > shell out to pipelines. Figure out what you actually need to learn 
> > from the directory listing and get that information directly, rather 
> > than trying to use two external commands and text parsing. It's far 
> > FAR easier, cleaner, and safer that way. 
> > 
> > ChrisA
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list
> > 
> 
> 
> -- 
> Regards, 
> Joseph Pareti - Artificial Intelligence consultant 
> Joseph Pareti's AI Consulting Services 
> https://www.joepareti54-ai.com/ 
> cell +49 1520 1600 209 
> cell +39 339 797 0644

I prefer LOLCODE for these kinds of tasks.

HAI 1.2
I HAS A VAR ITZ MAH_DIRECTORY
GIMMEH MAH_DIRECTORY

CAN HAS STDIO?
BOTH SAEM MAH_DIRECTORY AN 
"/media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48",
 O RLY?
  YA RLY, VISIBLE "FILEZ GO HERE!"
  NO WAI, VISIBLE "WTF IZ THAT?"
OIC

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


Re: Defining a Python enum in a C extension - am I doing this right?

2021-08-03 Thread Sean DiZazzo
On Tuesday, August 3, 2021 at 3:04:19 AM UTC-7, Bartosz Golaszewski wrote:
> On Sat, Jul 31, 2021 at 3:01 PM Bartosz Golaszewski  wrote: 
> > 
> > On Fri, Jul 30, 2021 at 2:41 PM Serhiy Storchaka  wrote: 
> > > 
> > > 23.07.21 11:20, Bartosz Golaszewski пише: 
> > > > I'm working on a Python C extension and I would like to expose a 
> > > > custom enum (as in: a class inheriting from enum.Enum) that would be 
> > > > entirely defined in C. 
> > > 
> > > I think that it would be much easier to define it in Python, and then 
> > > either import a Python module in your C code, or exec a Python code as a 
> > > string. 
> > > 
> > 
> > You mean: evaluate a string like this: 
> > 
> > ''' 
> > import enum 
> > 
> > class FooBar(enum.Enum): 
> > FOO = 1 
> > BAR = 2 
> > BAZ = 3 
> > ''' 
> > 
> > And then pull in the FooBar type from the resulting dictionary into my 
> > C code? Sounds good actually. I think I'll be able to add the FooBar 
> > type to another type's tp_dict too - because some enums I want to 
> > create will be nested in other classes. 
> > 
> > Bart
> Just a follow-up: this is how I did it eventually: 
> 
> ``` 
> #include  
> 
> typedef struct { 
> PyObject_HEAD; 
> } dummy_object; 
> 
> PyDoc_STRVAR(dummy_type_doc, "Dummy type in which the enum will be nested."); 
> 
> static PyTypeObject dummy_type = { 
> PyVarObject_HEAD_INIT(NULL, 0) 
> .tp_name = "pycenum.DummyType", 
> .tp_basicsize = sizeof(dummy_object), 
> .tp_flags = Py_TPFLAGS_DEFAULT, 
> .tp_doc = dummy_type_doc, 
> .tp_new = PyType_GenericNew, 
> .tp_dealloc = (destructor)PyObject_Del, 
> };
> PyDoc_STRVAR(module_doc, 
> "C extension module defining a class inheriting from enum.Enum."); 
> 
> static PyModuleDef module_def = { 
> PyModuleDef_HEAD_INIT, 
> .m_name = "pycenum", 
> .m_doc = module_doc, 
> .m_size = -1, 
> };
> static int add_foobar_enum(PyObject *module) 
> { 
> static const char *foobar_src = 
> "class FooBar(enum.Enum):\n" 
> " FOO = 1\n" 
> " BAR = 2\n" 
> " BAZ = 3\n"; 
> 
> PyObject *main_mod, *main_dict, *enum_mod, *result, *foobar_type; 
> int ret; 
> 
> main_mod = PyImport_AddModule("__main__"); 
> if (!main_mod) 
> return -1; 
> 
> main_dict = PyModule_GetDict(main_mod); 
> if (!main_dict) { 
> Py_DECREF(main_mod); 
> return -1;
> } 
> 
> enum_mod = PyImport_ImportModule("enum");
> if (!enum_mod) { 
> Py_DECREF(main_mod); 
> return -1; 
> } 
> 
> ret = PyDict_SetItemString(main_dict, "enum", enum_mod); 
> Py_DECREF(enum_mod); 
> if (ret) { 
> Py_DECREF(main_mod); 
> return -1; 
> } 
> 
> result = PyRun_String(foobar_src, Py_single_input, 
> main_dict, main_dict); 
> if (!result) { 
> Py_DECREF(main_mod); 
> return -1; 
> } 
> 
> foobar_type = PyDict_GetItemString(main_dict, "FooBar"); 
> if (!foobar_type) { 
> Py_DECREF(main_mod); 
> return -1; 
> } 
> 
> ret = PyDict_SetItemString(dummy_type.tp_dict, "FooBar", foobar_type); 
> Py_DECREF(foobar_type); 
> Py_DECREF(main_mod); 
> if (ret) 
> return -1; 
> 
> PyType_Modified(&dummy_type); 
> 
> return ret; 
> } 
> 
> PyMODINIT_FUNC PyInit_pycenum(void) 
> { 
> PyObject *module;
> int ret; 
> 
> module = PyModule_Create(&module_def); 
> if (!module) 
> return NULL; 
> 
> ret = PyModule_AddStringConstant(module, "__version__", "0.0.1");
> if (ret) { 
> Py_DECREF(module); 
> return NULL; 
> } 
> 
> ret = PyType_Ready(&dummy_type); 
> if (ret) { 
> Py_DECREF(module); 
> return NULL; 
> } 
> 
> ret = add_foobar_enum(module); 
> if (ret) { 
> Py_DECREF(module); 
> return NULL; 
> } 
> 
> Py_INCREF(&dummy_type); 
> ret = PyModule_AddObject(module, "DummyType", (PyObject *)&dummy_type); 
> if (ret) { 
> Py_DECREF(&dummy_type);
> Py_DECREF(module); 
> return NULL; 
> } 
> 
> return module; 
> }
> ``` 
> 
> Bart
No
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Farewell to Rob Collins

2016-11-16 Thread Sean Son
Rest in Peace Rob

On Wed, Nov 16, 2016 at 12:48 PM, Ben Finney 
wrote:

> "M.-A. Lemburg"  writes:
>
> > Rob was a true Pythonista from the heart. He will always be remembered
> > for his humor, great spirit and kindness.
>
> Robert and I had many conversations about the Bazaar version control
> system, and I owe to him my passion for distributed version control.
>
> When I needed to convince my workplace to try this strange new idea,
> Robert kindly donated his time to visit our offices and give a
> presentation on why distributed version control was better and why
> Bazaar was a good choice for us.
>
> He also inspired me to get serious about unit testing as a way to
> increase confidence in a code base.
>
> You touched many lives, and you are missed. Vale, Rob.
>
> --
>  \ “What you have become is the price you paid to get what you |
>   `\ used to want.” —Mignon McLaughlin |
> _o__)  |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


python 2 urlopen vs python 3 urlopen

2018-08-27 Thread Sean Darcy
python 2 :

python
Python 2.7.15 (default, May 15 2018, 15:37:31)
.
>>> import urllib2
>>> res = urllib2.urlopen('https://api.ipify.org').read()
>>> print res
www.xxx.yyy.zzz

python3

python3
Python 3.6.6 (default, Jul 19 2018, 16:29:00)
...
>>> from urllib.request import urlopen
>>> res = urlopen('https://api.ipify.org').read()
>>> print(res)
b'ww.xxx.yyy.zzz'

I'm expecting the python 2 result, just the ip address. How can I get
python 3 just to give the address, and not include  b'  '  ? I
know I can mess with string manipulation, but I want to keep it
simple.

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


Strange Python related errors for androwarn.py. Please help!

2016-05-24 Thread Sean Son
hello all

I am testing out a script called androwarn.py, which I downloaded from:

https://github.com/mz/androwarn

using the instructions found on:

https://github.com/mz/androwarn/wiki/Installation

When I ran the following commands to test the APK for AirBNB:


 python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
html -n


I received the following errors:

Traceback (most recent call last):
  File "androwarn.py", line 116, in 
main(options, arguments)
  File "androwarn.py", line 99, in main
data = perform_analysis(APK_FILE, a, d, x, no_connection)
  File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115, in
perform_analysis
( 'device_settings_harvesting',
gather_device_settings_harvesting(x) ),
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 96, in gather_device_settings_harvesting
result.extend( detect_get_package_info(x) )
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 79, in detect_get_package_info
flags = recover_bitwise_flag_settings(flag, PackageManager_PackageInfo)
  File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
recover_bitwise_flag_settings
if (int(flag) & option_value) == option_value :
ValueError: invalid literal for int() with base 10:
'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'


I am absolutely at a loss as to how I should fix these errors? Anyone have
any ideas? Sorry for just throwing this at you guys without warning, but
Ive been tasked with fixing this at work and I need assistance please!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-24 Thread Sean Son
Thanks for the reply.

Looks like I am screwed on this one lol

On Tue, May 24, 2016 at 3:31 PM, MRAB  wrote:

> On 2016-05-24 20:04, Sean Son wrote:
>
>> hello all
>>
>> I am testing out a script called androwarn.py, which I downloaded from:
>>
>> https://github.com/mz/androwarn
>>
>> using the instructions found on:
>>
>> https://github.com/mz/androwarn/wiki/Installation
>>
>> When I ran the following commands to test the APK for AirBNB:
>>
>>
>>  python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
>> html -n
>>
>>
>> I received the following errors:
>>
>> Traceback (most recent call last):
>>   File "androwarn.py", line 116, in 
>> main(options, arguments)
>>   File "androwarn.py", line 99, in main
>> data = perform_analysis(APK_FILE, a, d, x, no_connection)
>>   File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115, in
>> perform_analysis
>> ( 'device_settings_harvesting',
>> gather_device_settings_harvesting(x) ),
>>   File
>>
>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>> line 96, in gather_device_settings_harvesting
>> result.extend( detect_get_package_info(x) )
>>   File
>>
>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>> line 79, in detect_get_package_info
>> flags = recover_bitwise_flag_settings(flag,
>> PackageManager_PackageInfo)
>>   File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
>> recover_bitwise_flag_settings
>> if (int(flag) & option_value) == option_value :
>> ValueError: invalid literal for int() with base 10:
>>
>> 'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'
>>
>>
>> I am absolutely at a loss as to how I should fix these errors? Anyone have
>> any ideas? Sorry for just throwing this at you guys without warning, but
>> Ive been tasked with fixing this at work and I need assistance please!
>>
>> It looks like this issue:
>
> https://github.com/mz/androwarn/issues/10
>
> dating from 11 Dec 2014 and as yet unanswered.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-26 Thread Sean Son
Hello all

>From what I can tell from the error message that I received, line 257 of
the util.py script is causing the error.  Here is a link to this script:

https://github.com/mz/androwarn/blob/master/androwarn/util/util.py

I am not a python developer myself, unfortunately, so I have no idea how I
should fix this error.  All help is greatly appreciated!

Thanks

On Tue, May 24, 2016 at 3:46 PM, Sean Son 
wrote:

> Thanks for the reply.
>
> Looks like I am screwed on this one lol
>
> On Tue, May 24, 2016 at 3:31 PM, MRAB  wrote:
>
>> On 2016-05-24 20:04, Sean Son wrote:
>>
>>> hello all
>>>
>>> I am testing out a script called androwarn.py, which I downloaded from:
>>>
>>> https://github.com/mz/androwarn
>>>
>>> using the instructions found on:
>>>
>>> https://github.com/mz/androwarn/wiki/Installation
>>>
>>> When I ran the following commands to test the APK for AirBNB:
>>>
>>>
>>>  python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
>>> html -n
>>>
>>>
>>> I received the following errors:
>>>
>>> Traceback (most recent call last):
>>>   File "androwarn.py", line 116, in 
>>> main(options, arguments)
>>>   File "androwarn.py", line 99, in main
>>> data = perform_analysis(APK_FILE, a, d, x, no_connection)
>>>   File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115,
>>> in
>>> perform_analysis
>>> ( 'device_settings_harvesting',
>>> gather_device_settings_harvesting(x) ),
>>>   File
>>>
>>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>>> line 96, in gather_device_settings_harvesting
>>> result.extend( detect_get_package_info(x) )
>>>   File
>>>
>>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>>> line 79, in detect_get_package_info
>>> flags = recover_bitwise_flag_settings(flag,
>>> PackageManager_PackageInfo)
>>>   File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
>>> recover_bitwise_flag_settings
>>> if (int(flag) & option_value) == option_value :
>>> ValueError: invalid literal for int() with base 10:
>>>
>>> 'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'
>>>
>>>
>>> I am absolutely at a loss as to how I should fix these errors? Anyone
>>> have
>>> any ideas? Sorry for just throwing this at you guys without warning, but
>>> Ive been tasked with fixing this at work and I need assistance please!
>>>
>>> It looks like this issue:
>>
>> https://github.com/mz/androwarn/issues/10
>>
>> dating from 11 Dec 2014 and as yet unanswered.
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-26 Thread Sean Son
Here are the links to the other scripts mentioned in the error messages:

https://github.com/mz/androwarn/blob/master/androwarn/search/malicious_behaviours/device_settings.py

https://github.com/mz/androwarn/blob/master/androwarn/analysis/analysis.py

and the main androwarn.py script:

https://github.com/mz/androwarn/blob/master/androwarn.py

Hopefully those help in any troubleshooting steps that you all recommend to
me!

Thank you!

On Thu, May 26, 2016 at 1:25 PM, Sean Son 
wrote:

> Hello all
>
> From what I can tell from the error message that I received, line 257 of
> the util.py script is causing the error.  Here is a link to this script:
>
> https://github.com/mz/androwarn/blob/master/androwarn/util/util.py
>
> I am not a python developer myself, unfortunately, so I have no idea how I
> should fix this error.  All help is greatly appreciated!
>
> Thanks
>
> On Tue, May 24, 2016 at 3:46 PM, Sean Son <
> linuxmailinglistsem...@gmail.com> wrote:
>
>> Thanks for the reply.
>>
>> Looks like I am screwed on this one lol
>>
>> On Tue, May 24, 2016 at 3:31 PM, MRAB  wrote:
>>
>>> On 2016-05-24 20:04, Sean Son wrote:
>>>
>>>> hello all
>>>>
>>>> I am testing out a script called androwarn.py, which I downloaded from:
>>>>
>>>> https://github.com/mz/androwarn
>>>>
>>>> using the instructions found on:
>>>>
>>>> https://github.com/mz/androwarn/wiki/Installation
>>>>
>>>> When I ran the following commands to test the APK for AirBNB:
>>>>
>>>>
>>>>  python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3
>>>> -r
>>>> html -n
>>>>
>>>>
>>>> I received the following errors:
>>>>
>>>> Traceback (most recent call last):
>>>>   File "androwarn.py", line 116, in 
>>>> main(options, arguments)
>>>>   File "androwarn.py", line 99, in main
>>>> data = perform_analysis(APK_FILE, a, d, x, no_connection)
>>>>   File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115,
>>>> in
>>>> perform_analysis
>>>> ( 'device_settings_harvesting',
>>>> gather_device_settings_harvesting(x) ),
>>>>   File
>>>>
>>>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>>>> line 96, in gather_device_settings_harvesting
>>>> result.extend( detect_get_package_info(x) )
>>>>   File
>>>>
>>>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>>>> line 79, in detect_get_package_info
>>>> flags = recover_bitwise_flag_settings(flag,
>>>> PackageManager_PackageInfo)
>>>>   File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
>>>> recover_bitwise_flag_settings
>>>> if (int(flag) & option_value) == option_value :
>>>> ValueError: invalid literal for int() with base 10:
>>>>
>>>> 'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'
>>>>
>>>>
>>>> I am absolutely at a loss as to how I should fix these errors? Anyone
>>>> have
>>>> any ideas? Sorry for just throwing this at you guys without warning, but
>>>> Ive been tasked with fixing this at work and I need assistance please!
>>>>
>>>> It looks like this issue:
>>>
>>> https://github.com/mz/androwarn/issues/10
>>>
>>> dating from 11 Dec 2014 and as yet unanswered.
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-27 Thread Sean Son
Hello

Thank you for your reply. So the error isnt due to a bug in function
itself? It is due to a possible error in the Android APK file?  If that is
the case, it would take a while to figure this out. I tried contacted the
author of the project but I have yet to hear back from him .

Thanks



On Thu, May 26, 2016 at 8:31 PM, Michael Torrie  wrote:

> On 05/26/2016 05:57 PM, Michael Torrie wrote:
> > You could try emailing the author who's email address is listed on the
> > project's main github page.  I suspect the project itself is abandoned.
>
> Ahem. That should have been whose. Sigh.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


best Pythonic way to do this sort: Python newb

2005-10-09 Thread Sean Berry
Hello all

I have build a list that contains data in the form below
-- simplified for question --
myList = [[value1, value2, value3],[value1, value2, value3], ...]

I have a function which takes value3 from the lists above and returns
another value.  I want to use this returned value to sort the lists.

So, my resultant list would be ordered by the return value of the
function with value3 as its argument.

>From a relative Python newb, what is the best way to do this?

Thanks for any help offered. 


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


Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Sean Berry

"Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Sean Berry" <[EMAIL PROTECTED]> writes:
>> myList = [[value1, value2, value3],[value1, value2, value3], ...]
>>
>> I have a function which takes value3 from the lists above and returns
>> another value.  I want to use this returned value to sort the lists.
>>
>> So, my resultant list would be ordered by the return value of the
>> function with value3 as its argument.
>>
>> From a relative Python newb, what is the best way to do this?
>
> def get_key(x): return x[2]
> sorted_list = sorted(myList, key=get_key)

Sorry if I am missing something.  But. what is sorted here?

My simplified function looks like this

def myFunction( myNumber ):
"do some math calculations to myNumber"
return "result of calculations"

So, I want to sort myList by the return of myFunction( value3 )

I tried doing the following... with no luck so far
myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2]))

Thanks for any help.


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


question about timestamp and MySQLdb

2005-10-19 Thread Sean Berry
I am using MySQLdb to connect to a database and retrieve a timestamp from a 
table.  The problem is I want the timestamp as a long, unformatted and all.

In the table I have a timestamp like this
20051019111617

But, when I retrieve the value and print it I get
 2005-10-19 11:16:17

I want the numeric version, not the converted date.  Any suggestions? 


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


tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
hi all

i recently wrote a script that implements a puzzle. the interface
mostly consists of a bunch of colored disks on a tkinter canvas. the
problem is that the disks change their colors in ways other than the
way they're supposed to. it certainly isn't just a bug in my script,
since i can sometimes change the color of certain disks just by taking
focus off of the window and then bringing it back again! does this
sound like some known bug in tkinter? and if so, is there a recommended
way of working around it? if it matters, i'm using python 2.3 under
windows 95. any advice will be much appreciated.

peace

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


Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
i'm using the canned colors ("pink", "orange", etc). should i try
changing to explicit color specifications to see if that makes a
difference? i'm not sure what the other guy meant by a "soft toy", but
i take it the idea is to try and construct a correctness proof for the
script, and see what keeps it (the proof) from working. it's a sound
idea, of course, but the script is pretty darn straightforward, as you
can see (below). anyway, i'll let you know how it turns out.

peace




green  = 'green'

orange = 'orange'

pink   = 'pink'

yellow = 'yellow'

red= 'red'

blue   = 'blue'



fb = 'frontback'

ud = 'updown'

lr = 'leftright'



def select(x,a,b): return b[a.index(x)]

def frontback(orientation): return
select(orientation,[fb,ud,lr],[fb,lr,ud])

def updown(orientation): return
select(orientation,[fb,ud,lr],[lr,ud,fb])

def leftright(orientation): return
select(orientation,[fb,ud,lr],[ud,fb,lr])



class cell:

def __init__(self, circlecolor, pointercolor, orientation,
coordinates):

self.circlecolor  = circlecolor

self.pointercolor = pointercolor

self.orientation  = orientation

self.coordinates  = coordinates

def endpoint(self):

a,b = self.coordinates

if self.orientation==fb:

if abs(a)==1: return [2*a,2*b]

if abs(a)==2: return [a/2,b/2]

if self.orientation==ud: return [+a,-b]

if self.orientation==lr: return [-a,+b]



class cube:

def __init__(self):

self.ful = cell(green,  blue, fb, [-2,+2])

self.fur = cell(orange, blue, fb, [+2,+2])

self.fdl = cell(pink,   blue, fb, [-2,-2])

self.fdr = cell(yellow, blue, fb, [+2,-2])

self.bul = cell(green,  red,  fb, [-1,+1])

self.bur = cell(orange, red,  fb, [+1,+1])

self.bdl = cell(pink,   red,  fb, [-1,-1])

self.bdr = cell(yellow, red,  fb, [+1,-1])

self.cells =
[self.ful,self.fur,self.fdl,self.fdr,self.bul,self.bur,self.bdl,self.bdr]

def redraw(self,*cells):

for x in cells:

A = x.coordinates

B = x.endpoint()

erase(*A)

drawpointer(color=x.pointercolor,*(A+B))

drawcircle(color=x.circlecolor,*A)

def display(self):

self.redraw(*self.cells)

def cycle(self,a,b,c,d,funct):

x = d.circlecolor

y = d.pointercolor

z = funct(d.orientation)

d.circlecolor  = c.circlecolor

d.pointercolor = c.pointercolor

d.orientation  = funct(c.orientation)

c.circlecolor  = b.circlecolor

c.pointercolor = b.pointercolor

c.orientation  = funct(b.orientation)

b.circlecolor  = a.circlecolor

b.pointercolor = a.pointercolor

b.orientation  = funct(a.orientation)

a.circlecolor  = x

a.pointercolor = y

a.orientation  = z





rubik = cube()



def F1_():
rubik.cycle(rubik.ful,rubik.fur,rubik.fdr,rubik.fdl,frontback)

def F2_():
rubik.cycle(rubik.fdl,rubik.fdr,rubik.fur,rubik.ful,frontback)

def B1_():
rubik.cycle(rubik.bdl,rubik.bdr,rubik.bur,rubik.bul,frontback)

def B2_():
rubik.cycle(rubik.bul,rubik.bur,rubik.bdr,rubik.bdl,frontback)



def U1_(): rubik.cycle(rubik.bul,rubik.bur,rubik.fur,rubik.ful,updown)

def U2_(): rubik.cycle(rubik.ful,rubik.fur,rubik.bur,rubik.bul,updown)


def D1_(): rubik.cycle(rubik.bdl,rubik.bdr,rubik.fdr,rubik.fdl,updown)

def D2_(): rubik.cycle(rubik.fdl,rubik.fdr,rubik.bdr,rubik.bdl,updown)



def L1_():
rubik.cycle(rubik.ful,rubik.bul,rubik.bdl,rubik.fdl,leftright)

def L2_():
rubik.cycle(rubik.fdl,rubik.bdl,rubik.bul,rubik.ful,leftright)

def R1_():
rubik.cycle(rubik.fur,rubik.bur,rubik.bdr,rubik.fdr,leftright)

def R2_():
rubik.cycle(rubik.fdr,rubik.bdr,rubik.bur,rubik.fur,leftright)



def F1(): F1_(); rubik.redraw(rubik.ful,rubik.fur,rubik.fdr,rubik.fdl)

def F2(): F2_(); rubik.redraw(rubik.fdl,rubik.fdr,rubik.fur,rubik.ful)

def B1(): B1_(); rubik.redraw(rubik.bdl,rubik.bdr,rubik.bur,rubik.bul)

def B2(): B2_(); rubik.redraw(rubik.bul,rubik.bur,rubik.bdr,rubik.bdl)

def U1(): U1_(); rubik.redraw(rubik.bul,rubik.bur,rubik.fur,rubik.ful)

def U2(): U2_(); rubik.redraw(rubik.ful,rubik.fur,rubik.bur,rubik.bul)

def D1(): D1_(); rubik.redraw(rubik.bdl,rubik.bdr,rubik.fdr,rubik.fdl)

def D2(): D2_(); rubik.redraw(rubik.fdl,rubik.fdr,rubik.bdr,rubik.bdl)

def L1(): L1_(); rubik.redraw(rubik.ful,rubik.bul,rubik.bdl,rubik.fdl)

def L2(): L2_(); rubik.redraw(rubik.fdl,rubik.bdl,rubik.bul,rubik.ful)

def R1(): R1_(); rubik.redraw(rubik.fur,rubik.bur,rubik.bdr,rubik.fdr)

def R2(): R2_(); rubik.redraw(rubik.fdr,rubik.bdr,rubik.bur,rubik.fur)



def solve():

rubik.__init__()

rubik.display()



def scramble():

n = 15

from random import randint

f = [F1_,F2_,B1_,B2_,U1_,U2_,D1_,D2_,L1_,L2_,R1_,R2_]

for i in range(n): f[randint(0,11)]()

rubik.display()



canvaswidth = 380

canvasheight = 330



def c

Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
hi ron

changing from english words to hexadecimal numerals did the trick for
me, so everything's cool now. thanks for looking at it.

peace

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


Re: Getting rid of "self."

2005-01-07 Thread Sean Ross
"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Thank you for your replies. But they don't deal with my original
question. :) I have read the thousands of posts all saying "self is
good" and they are right. But this time I want to be different m-kay?
I figure that there might be some way to solve my problem by doing
this:
[snip ...]
But beyond that, I have no idea and I would be grateful if someone
would like to help me with it.


http://starship.python.net/crew/mwh/hacks/selfless.py


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


Re: tuples vs lists

2005-01-08 Thread Sean Dolan
worzel wrote:
I get what the difference is between a tuple and a list, but why would I 
ever care about the tuple's immuutability?
Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or 
tomato kind of thing)
TIA 


I use the Festival Speech Synthesis System to learn pronunciations 
sometimes. The American english voice is quite accurate.

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


mysterious buggy behavior

2005-01-08 Thread Sean McIlroy
While fiddling with a little script I ran into a problem that baffles
me completely. Maybe I'm missing something completely obvious, and
somebody out there can diagnose the problem at a glance. Anyway,
that's the hope. Here's the code (it plays tic tac toe):


"""
Something goes wrong with the "time saver" section of the function
makeMove. The section
needs to be there to ensure that the computer makes its move in a
reasonable amount of
time when it is making the first or the second move. That section of
code is so simple
that I can't even imagine what could be going wrong with it.
"""

"""
012
345
678
"""

ex,oh,blank = range(3)
lines = [(0,3,6),(1,4,7),(2,5,8),(0,1,2),(3,4,5),(6,7,8),(0,4,8),(2,4,6)]
 
def subs(board,player,i):
b = board[:]
b[i] = player
return b   
  
def valMove(board):
winners = [x for x in (ex,oh) for L in lines if
board[L[0]]==board[L[1]]==board[L[2]]==x]
if winners: return winners[0]==ex and (+1,None) or (-1,None)
if board.count(blank)==0: return (0,None)
player = (oh,ex)[board.count(ex)==board.count(oh)]
optimal = (min,max)[player==ex]
blankIndices = [i for i in range(9) if board[i]==blank]
return optimal([(valMove(subs(board,player,i))[0],i) for i in
blankIndices])

BOARD = [blank]*9

def clickButton(i):
def f():
BOARD[i] = ex
(topButtons,midButtons,botButtons)[i//3][i%3]['text'] = 'X'
return f

def newGame():
BOARD = [blank]*9
for x in topButtons+midButtons+botButtons: x['text'] = ''

def makeMove():
i = None
## 
if BOARD.count(blank)>=8:
for j in [4,0,2,6,8]:
if BOARD[j]==blank: i = j; break
## 
if i==None: i = valMove(BOARD)[1]
BOARD[i] = oh
(topButtons,midButtons,botButtons)[i//3][i%3]['text'] = 'O'

from Tkinter import *

root = Tk()
###
topRow = Frame(master=root)
topButtons = [Button(master=topRow,width=1,command=clickButton(i)) for
i in range(3)]
###
midRow = Frame(master=root)
midButtons = [Button(master=midRow,width=1,command=clickButton(3+i))
for i in range(3)]
###
botRow = Frame(master=root)
botButtons = [Button(master=botRow,width=1,command=clickButton(6+i))
for i in range(3)]
###
map(lambda x: x.pack(side=TOP),[topRow,midRow,botRow])
map(lambda x: x.pack(side=LEFT),topButtons + midButtons + botButtons)
###
dummyRow = Frame(master=root)
placeHolder = Label(master=dummyRow,text='')
dummyRow.pack(side=TOP)
placeHolder.pack(side=TOP)
###
ctrlRow = Frame(master=root)
computerMoveButton = Button(master=ctrlRow,text='computer
move',command=makeMove)
newGameButton = Button(master=ctrlRow,text='new game',command=newGame)
ctrlRow.pack(side=TOP)
computerMoveButton.pack(side=TOP)
newGameButton.pack(side=TOP)
###
root.title('tic tac toe')
root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Old Paranoia Game in Python

2005-01-10 Thread Sean P.Kane
I ported the old (and long since removed) game from the bsd-game 
pacakge called, Paranoia, based on the old Paranoia role playing game 
from C to Python as a simple exercise in learning the language and pure 
late night boredom. Anyways, here it is for anyone looking for a few 
minutes of nostalgia. I may get around to posting this at 
http://homepage.mac.com/spkane/ or http://www.spkane.org/, but for now 
here it is. Improvements or corrections, welcome.

Thanks,
Sean
-Cut Here-
#!/usr/bin/env python
#
#
# -*- encoding = 'utf-8' -*-
#
#
# Command Line GCS Upgrade Application
# 
# This is a port of paranoia from the old bsd-games package.
#
#
# HISTORY
# ===
#
# 1.2 - 03 Jan 2005
# + Initially started porting application
#
# Requires
# 
# 1) Python 2.3
'''\
usage: paranoia
'''
__author__ = 'Sean P. Kane <[EMAIL PROTECTED]>'
__copyright__  = '''This is a solo paranoia game taken from the Jan/Feb 
issue (No 77) of SpaceGamer/FantasyGamer magazine.

Article by Sam Shirley.
Originally implemented in C on Vax 11/780 under UNIX by Tim Lister
Ported to Python on an Apple Powerbook G4 by Sean P. Kane
This is a public domain adventure and may not be sold for profit'''
__date__  = '01/03/2005'
#Also change version at top of main()
__version__= '1.2'
#the basics
import sys
#For Dice Rolling
import random
#new argument parsing library
from optparse import OptionParser
moxie = 13
agility = 15
maxkill = 7 # The maximum number of UV's you can kill
clone = 1
page = 1
computer_request = 0
ultra_violet = 0
action_doll = 0
hit_points = 10
read_letter = 0
plato_clone = 3
blast_door = 0
killer_count = 0
def instructions():
   print """Welcome to Paranoia!
HOW TO PLAY:
   Just press  until you are asked to make a choice.
   Select 'a' or 'b' or whatever for your choice, then press .
   You may select 'p' at any time to get a display of your statistics.
   Always choose the least dangerous option.  Continue doing this until
   you win. At times you will use a skill or engage in combat and will
   be informed of the outcome.  These sections will be self explanatory.
   HOW TO DIE:
   As Philo-R-DMD you will die at times during the adventure.
   When this happens you will be given an new clone at a particular
   location. The new Philo-R will usually have to retrace some of
   the old Philo-R\'s path hopefully he won\'t make the same mistake
   as his predecessor.
   HOW TO WIN:
   Simply complete the mission before you expend all six clones.
   If you make it, congratulations.
   If not, you can try again later.
"""
def character():
   print 
""""===
The 

The Character : Philo-R-DMD %s
Primary Attributes  Secondary Attributes
===
Strength . 13   Carrying Capacity . 30
Endurance  13   Damage Bonus ... 0
Agility .. 15   Macho Bonus ... -1
Manual Dexterity . 15   Melee Bonus .. +5%%
Moxie  13   Aimed Weapon Bonus .. +10%%
Chutzpah .. 8   Comprehension Bonus .. +4%%
Mechanical Aptitude .. 14   Believability Bonus .. +5%%
Power Index .. 10   Repair Bonus . +5%%
===
Credits: 160Secret Society: IlluminatiSecret Society Rank: 1
Service Group: Power Services   Mutant Power: Precognition
Weapon: laser pistol to hit, 40%% type, L Range, 50m Reload, 6r Malfnt, 00
Skills: Basics 1(20%%), Aimed Weapon Combat 2(35%%), Laser 3(40%%),
   Personal Development 1(20%%), Communications 2(29%%), 
Intimidation 3(34%%)
Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red),
  Notebook & Stylus, Knife, Com Unit 1, Jump suit,
  Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring,
  Utility Belt & Pouches
===
""" % clone

def page1():
  global page
  print """You wake up face down on the red and pink checked E-Z-Kleen 
linoleum floor.
You recognise the pattern, it's the type preferred in the internal security
briefing cells.  When you finally look around you, you see that you are alone
in a large mission briefing room.
"""
  page = 57
  more()

def page2():
  global page
  global computer_re

unicode mystery

2005-01-10 Thread Sean McIlroy
I recently found out that unicode("\347", "iso-8859-1") is the
lowercase c-with-cedilla, so I set out to round up the unicode numbers
of the extra characters you need for French, and I found them all just
fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode
characters from 0 to 900 without finding it; then I looked at
www.unicode.org but the numbers I got there (0152 and 0153) didn't
work. Can anybody put a help on me wrt this? (Do I need to give a
different value for the second parameter, maybe?)

Peace,
STM

PS: I'm considering looking into pyscript as a means of making
diagrams for inclusion in LaTeX documents. If anyone can share an
opinion about pyscript, I'm interested to hear it.

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


reusing Tkinter Canvases

2005-01-14 Thread Sean McIlroy
I'd like to save one Tkinter Canvas in order to use it on another
Canvas later. The problem is that it gets saved as EPS but it needs to
be GIF to be reuseable. How can I convert that format?

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Java Integer.ParseInt translation to python

2005-01-31 Thread Sean Blakey
On Mon, 31 Jan 2005 19:23:35 -0500, jose isaias cabrera
<[EMAIL PROTECTED]> wrote:
> 
> Greetings!
> 
> I've looked through the internet (not long, though) but I have not been able
> to find a python translation to
> 
> buffer[0] = (byte)Integer.parseInt(string,16);
> 
> Has anyone ported any java programs to python and has translated this?
> 
> any help would be greatly appreciated.
> 
> thanks.
> 
> josé
> 

buffer[0] = int(string, 16)

http://docs.python.org/lib/built-in-funcs.html

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do you do arrays

2005-02-01 Thread Sean Blakey
On Tue, 01 Feb 2005 10:52:45 -0800, Thomas Bunce <[EMAIL PROTECTED]> wrote:
> I am new at Pyton and I am learning from book not classes
> so please forgive my being slow
> 
> The below does not work I get an Error of  File
> "Matrix[index] = k
> NameError: name 'iMatrix' is not defined"
> 
> while  index < majorlop1:
>index = index + 1
>k = random.choice(listvalues) + 1
>iMatrix[index] = k
> 
> The book statement of
>  array(typecode, initializer) does not make sence
> to me how it henerates ore relaes to the org name
> for the array.
> 
> Thank You
>  Tom
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
Like any other variable, you need to declare iMatrix before you use it:
$ python
Python 2.4 (#1, Dec 28 2004, 12:08:51) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> import array
>>> index = 0
>>> majorlop1 = 4
>>> iMatrix = array.array('b')
>>> listvalues = [1, 2, 3, 4]
>>> while index < majorlop1:
... index = index + 1
... k = random.choice(listvalues) + 1
... iMatrix.append(k) 
... 
>>> iMatrix
array('b', [3, 5])
>>> 

You should probably look at the wealth of information at
http://www.python.org/doc - the tutorial is a good start on how to use
the language, and the library reference has much more depth on the
array module.
http://docs.python.org/lib/module-array.html
-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


Save the Canvas!

2005-02-01 Thread Sean McIlroy
I'd like to be able to save a Tkinter Canvas in a format other than
postscript (preferably gif). Is there a tool out there for
accomplishing that? Any help will be much appreciated.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two questions on lambda:

2005-06-24 Thread Sean McIlroy
def PRINT(x): print x
f = lambda: PRINT("hello")

###

def let(x,y):
globals()[x] = y
return True

f = lambda x: let('y',x*x) and y+y

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Sean McIlroy

Tom Anderson wrote:

> So, if you're a pythonista who loves map and lambda, and disagrees with
> Guido, what's your background? Functional or not?

glad you asked. personally i don't know lisp (or scheme), but now i've
decided to learn it, because eventually it will no longer be possible
in python to pass functions as arguments or return them as values. the
education sig will have to change its motto to "computer programming
for every C-programmer". until then hangers-on like myself can use
home-grown substitutes for the functional constructs (examples below),
but in my opinion the best thing is to migrate as soon as possible. the
real programmers are squeezing us out. now is the time to abandon
python for an intelligent language (macros! real conditional evaluation
instead of the and/or kluge!)

def LISTCOMP(f,s,g):
reval = []
for x in s:
if g(x):
reval.append(f(x))
return reval

def LAMBDA(arguments,value):
symbols = arguments.split(',')
def reval(*args):
for i in range(len(args)):
locals()[symbols[i]] = args[i]
return eval(value)
return reval

def MAP(f,s):
return LISTCOMP(f,s,LAMBDA('x','True'))

def FILTER(f,s):
return type(s)(LISTCOMP(LAMBDA('x','x'),s,f))

def REDUCE(f,s,t):
if not s: return t
return f(s[0],REDUCE(f,s[1:],t))

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Sean McIlroy
Peter Hansen wrote:

> Sean, what gave you the impression this would change?

just inductive reasoning. i've been wrong before (like anyone who makes
that claim), and i'm a former python enthusiast, so my judgement must
be colored to some extent  by bitterness. maybe they have solid reasons
for scrapping the functional constructs. but to me it seems like
they're eliminating them just because they offend the sensibilities of
C-programmers. (i mean those stereotypical C-programmers, baffled by
recursion and the like, who don't want to be reproached with the fact
of their mathematical illiteracy.) if that's the case then list
comprehensions and/or "first class functions" are likely to be the next
target. even if they're not, it's pretty clear that python is leaving
its multiparadigmatic origins behind. "do it our way," the pundits are
effectively saying, "or get out". for my part, i'm getting out.

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


keywords for optional args in extension modules

2005-08-11 Thread Sean Richards

Python 2.3.4 (#1, May 29 2004, 17:05:23) 
[GCC 3.3.3] on linux2

Getting some strange behaviour with keyword arguments for optional
arguments in extension modules. See the simple test case below

8<--
#include "Python.h"

static PyObject *
keywdarg_test(PyObject *self, PyObject *args, PyObject *keywds)
{
  int one;
  unsigned int two = 2;
  int three = 3;

  static char *kwlist[] = {"one", "two", "three", NULL};
  if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|Ii", kwlist,
   &one, &two, &three))
return NULL;

Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef keywdarg_methods[] = {
  {"test", (PyCFunction)keywdarg_test, METH_VARARGS | METH_KEYWORDS},
  {NULL, NULL, 0, NULL}
};

void
initkeywdarg(void)
{
  Py_InitModule("keywdarg", keywdarg_methods);
}
8<-- 

Compile the module

$ cc -g -c keywdarg.c -I/usr/include/python2.3
$ ld -shared -o keywdarg.so  keywdarg.o


Test it

In [1]: from keywdarg import *

In [2]: test(1)

In [3]: test(1,two=2)

In [4]: test(1,two=2,three=3)

In [5]: test(1,three=3,two=2)

In [6]: test(1,three=3)
---
exceptions.TypeError Traceback (most recent 
call last)

/home/sean/research/code/framework/wiener/ 

TypeError: argument 2, item 1074941247, item 1079307903 impossible


However if I change the order of the optional arguments so the unsigned
int is last as below then it works fine.

if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|iI", kwlist,
 &one, &three, &two))


This seems buggy. Python 2.3 is getting a bit old now but do later later
versions still exhibit this behaviour?

Cheers, Sean

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


Re: python code with indention

2005-02-09 Thread Sean Blakey
On Wed, 09 Feb 2005 10:10:29 -0800 (PST), Xah Lee <[EMAIL PROTECTED]> wrote:
> i thought it is trivial for the Python parser to spit out a version
> with matching brackets. Similarly, perhaps some opensourcing student
> has modified a parser to read in a matching brackets delimited version
> of Python.
> 
>  Xah
>  [EMAIL PROTECTED]
>  http://xahlee.org/PageTwo_dir/more.html
> 

Well, there's always the pindent.py script. Get the python source, and
look at Tools/scripts/pindent.py

This isn't an alternate parser, but it can turn a python script with
end-block comments and no indentation into a correctly indented python
script.

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


two questions - no common theme

2005-02-09 Thread Sean McIlroy
And now for a pair of questions that are completely different:

1) I'd like to be able to bind callbacks to presses of the arrow
buttons on the keyboard. How do you say that in Tkinter?

2) The function 'listdir' in os.path returns a list of all the files
in the given directory - how do I get hold of a list of its
subdirectories?

Any help will be greatly appreciated.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


'modal dialogs' with Tkinter

2005-02-22 Thread Sean McIlroy
I'd like to have a function f such that, when f is invoked, a Tk
window w is presented in which a number of variables can be modified,
and f returns the values that are indicated by the relevant
menus/checkbuttons/etc at the time w gets closed. I've tried various
ways of doing this, without success. Any assistance would be greatly
appreciated.

Peace,
Sean McIlroy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
I can't claim to have studied your problem in detail, but I get
reasonable results from the following:

filename = 'Errors.txt'
S = open(filename,'r').read().split()
f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or
x
open(filename,'w').write(' '.join(map(f,S)))

HTH

-


[EMAIL PROTECTED] wrote in message news:<[EMAIL PROTECTED]>...
> Hello NG,
> 
>   probably this is a basic question, but I'm going crazy... I am unable
> to find an answer. Suppose that I have a file (that I called "Errors.txt")
> which contains these lines:
> 
> MULTIPLY
>   'PERMX'  @PERMX1  1 34  1  20  1 6 /
>   'PERMX'  @PERMX2  1 34  21 41  1 6 /
>   'PERMX'  @PERMX3  1 34  1  20  7 14/
>   'PERMX'  @PERMX4  1 34  21 41  7 14/
>   'PERMX'  @PERMX5  1 34  1  20 15 26/
>   'PERMX'  @PERMX6  1 34  21 41 15 26/
>   'PERMX'  @PERMX7  1 34  1  20 27 28/
>   'PERMX'  @PERMX8  1 34  21 41 27 28/
>   'PERMX'  @PERMX9  1 34  1  20 29 34/
>   'PERMX'  @PERMX10  1 34  21 41 29 34/
>   'PERMX'  @PERMX11  1 34  1  20 35 42/
>   'PERMX'  @PERMX12  1 34  21 41 35 42/
>   'PERMX'  @PERMX13  1 34  1  20 43 53/
>   'PERMX'  @PERMX14  1 34  21 41 43 53/
>   'PERMX'  @PERMX15  1 34  1  20 54 61/
>   'PERMX'  @PERMX16  1 34  21 41 54 61/
> /
> 
> I would like to replace all the occurrencies of the "keywords" (beginning
> with the @ (AT) symbol) with some floating point value. As an example, this
> is what I do:
> 
> #  --- CODE BEGIN
> 
> import re
> import string
> 
> # Set Some Dummy Parameter Values
> parametervalues = range(1, 17)
> 
> # Open And Read The File With Keywords
> fid = open("Errors.txt","rt")
> onread = fid.read()
> fid.close()
> 
> # Find All Keywords Starting with @ (AT)
> regex = re.compile("[EMAIL PROTECTED]", re.IGNORECASE)
> keywords = regex.findall(onread)
> 
> counter = 0
> 
> # Try To Replace The With Floats
> for keys in keywords:
> pars = parametervalues[counter]
> onread = string.replace(onread, keys, str(float(pars)))
> counter = counter + 1
> 
> # Write A New File With Replaced Values
> fid = open("Errors_2.txt","wt")
> fid.write(onread)
> fid.close()
> 
> #  --- CODE END
> 
> 
> Now, I you try to run this little script, you will see that for keywords
> starting from "@PERMX10", the replaced values are WRONG. I don't know why,
> Python replace only the "@PERMX1" leaving out the last char of the keyword
> (that are 0, 1, 2, 3, 4, 5, 6 ). These values are left in the file and I
> don't get the expected result.
> 
> Does anyone have an explanation? What am I doing wrong?
> 
> Thanks to you all for your help.
> 
> Andrea.
> 
> --
>  Message for the recipient only, if received in error, please notify the
> sender and read http://www.eni.it/disclaimer/
-- 
http://mail.python.org/mailman/listinfo/python-list


canvassing for assistance

2005-02-28 Thread Sean McIlroy
Hi all!

I've written a utility for making diagrams. It could also be a good
environment for experimenting with a Tk canvas, so I'm including the
code here (see below). The problem is that, when I save a canvas and
include the resulting postscript file in a LaTeX document, I often
find that the right edge of the canvas has been cut off and/or that
there's a bunch of extra space at the bottom that forces the picture
to take up a whole page just by itself. The Introduction to Tkinter
lists a bunch of options for the Canvas postscript method, but it
doesn't say anything about the semantics of any of them, and there are
several that sound like they could be what I need. So, if anybody
knows how to exercise finer control over the Canvas postscript method,
I'd be grateful to hear about it.

Peace,
STM


###
## FRESH SHELL: import canvasser
## (so that text can be copied from the shell)
###

pencil = 1
eraser = 10
color = 'black'

def save():
from tkSimpleDialog import askstring
filename = askstring('save diagram','enter name of diagram: ') +
'.eps'

canvas.postscript(file=filename,width=100,height=100,pagewidth=100,pageheight=100)

def circle(x,y,radius=25,color=None): 
r = radius
return canvas.create_oval(x-r,y-r,x+r,y+r,fill=color)

#

__P__ = None
__I__ = None

def draw(event):   
global __P__
Q = [event.x,event.y]
canvas.create_line(__P__[0],__P__[1],Q[0],Q[1],width=pencil,fill=color)
__P__ = Q
   
def erase(event):
r = eraser
x,y = event.x,event.y
for x in canvas.find_overlapping(x-r,y-r,x+r,y+r):
canvas.delete(x)

def carry(event):
if __I__==None: return
C = canvas.coords(__I__)
x,y = event.x,event.y
if len(C)==2: canvas.coords(__I__,x,y)
else:
a,b = C[:2]
f = lambda i: ( i%2 and [y-b] or [x-a] ) [0]
D = [x,y] + [C[i] + f(i) for i in range(2,len(C))]
canvas.coords(__I__,*D)

def scale(event):
C = canvas.coords(__I__)
if len(C)<>4: return
canvas.coords(__I__,C[0],C[1],event.x,event.y)

def point(event):
codeArea.insert(INSERT,str(event.x) + ',' + str(event.y))

def item(event):
codeArea.insert(INSERT,str(canvas.find_closest(event.x,event.y)[0]))
  
def mouseDown(event):
global __P__,__I__
m = mode.get()
if   m==0: __P__ = [event.x,event.y]
elif m==2: point(event)
elif m==3: item(event)
elif m>=4: __I__ = canvas.find_closest(event.x,event.y)

def mouseDrag(event):
m = mode.get()
if   m==0: draw(event)
elif m==1: erase(event)
elif m==4: carry(event)
elif m==5: scale(event)

def mouseUp(event): 
global __P__,__I__
__P__ = None
__I__ = None

def runCode(dummy):
x = codeArea.get()
y = [i for i in range(len(x)) if x[i]=='=' and
x[:i].count('(')==0]
z = y and x[:y[0]] + '=' + x[y[0]+1:] or x
print '>>> ' + z
try: exec z in globals() 
except: print 'ERROR'
codeArea.delete(0,END)

from Tkinter import *
print '*'*80
print 'REMINDER: canvas; pencil,eraser,color; save,circle'
print '*'*80 
root = Tk()
canvas = Canvas(root,background='white')
canvas.bind('',mouseDown)
canvas.bind('',mouseDrag)
canvas.bind('',mouseUp)
canvas.pack(side=TOP,expand=1,fill=BOTH)
codeArea = Entry(root,font=6)
codeArea.pack(side=TOP,expand=1,fill=X)
codeArea.bind('',runCode)
ctrl = Frame(root)
mode = IntVar()
Radiobutton(ctrl,indicatoron=0,variable=mode,value=0,text='draw').pack(side=LEFT)
Radiobutton(ctrl,indicatoron=0,variable=mode,value=1,text='erase').pack(side=LEFT)
Radiobutton(ctrl,indicatoron=0,variable=mode,value=2,text='point').pack(side=LEFT)
Radiobutton(ctrl,indicatoron=0,variable=mode,value=3,text='item').pack(side=LEFT)
Radiobutton(ctrl,indicatoron=0,variable=mode,value=4,text='carry').pack(side=LEFT)
Radiobutton(ctrl,indicatoron=0,variable=mode,value=5,text='scale').pack(side=LEFT)
ctrl.pack(side=TOP,pady=10)
root.title('canvasser')
root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
Alright, now it's too much. It's not enough that you're eliminating it
from the language, you have to stigmatize the lambda as well. You
should take some time to reflect that not everybody thinks the same
way. Those of us who are mathematically inclined like the lambda
because it fits in well with the way we already think. And besides, it
amounts to an explicit declaration that the function in question has
no side effects. And besides, it adds flexibility to the language. Go
ahead and throw it away, but you're making python less accessible for
those of us whose central concern is something other than programming.
("Single line" indeed!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need direction to kill a virus

2005-03-02 Thread Sean Blakey
On Wed, 2 Mar 2005 17:46:44 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
> Four steps, meant to help, really.
> 
> 1. shut down your computer
> 2. erase your hard drive
> 3. install linux with a firewall
> 4. reboot
> 
> You can always run your beloved window$ under vmware.
> 
> Alternately, get a Mac.
> 
> You will never have another problem like this again. The real virus is your
> operating system.
> 
> Sorry for the brutally honest and yet ultimately helpful answer. If it angers
> you as it does some, well, then you may actually deserve what you get.
> 
> James
> 
> (Living M$ free for 7 years and never been happier.)
> 
> 

Based on the mailing lists I've found your name on and the messages
there, I'm going to give you the benefit of the doubt and assume that
shouting "Don't use windows!" in your general direction would be just
beating a dead horse.

Unfortunately, I don't know of an easy way to remove unidentified 
viruses from an already-infected computer. I really doubt there is a
five-minute guru answer, and unless you find such a solution, you will
probably have to resort to the reformat/reinstall route. You mention
that you have already reinstalled, but do not make clear whether or
not you reformatted your hard drive first - if the problem is in a
file not overwritten by the windows install, it could easily survive a
reinstall without a reformat.

Short of switching to a different operating system, there are a few
steps I can recommend to help defend against malicious attachments and
such:
1) Never, ever, ever use Outlook. Outlook Express is
almost-but-not-quite as bad. Microsoft made several design decisions
to "enhance" the user experience which have resulted in pretty much
every email virus and worm, ever. As an email client for people used
to Outlook Express, I heartily reccomend Mozilla Thunderbird
(http://www.mozilla.org/products/thunderbird/).
2) Use a good spamfilter to automate the process of sorting out junk
from your mail. After a little training, the Bayesian filter built-in
to Thunderbird works well enough for my purposes.
3) If you must use windows, firewalling and virus scanning are
essential. You seem to already have that part, plus a certain paranoia
about attachments that puts you well ahead of the curve.
4) Similar to #1, you should NEVER surf the web in Internet Explorer.
Again, this is primarily because Microsoft chose to include features
(ActiveX controls in web pages) that have led to an unmanagable number
of security problems. Firefox (http://www.getfirefox.com) is a
wonderful alternative browser for Windows users, and will be available
to you on other platforms if you ever choose to switch to an OS less
beleagured by viruses, trojans, and spyware.
5) You seem appropriately paranoid about attachments, although I do
have to wonder what kind of message was sent to you that made yo uwant
to open "details.txt" in the first place. I think you will appreciate
an email client that shows you the file type and asks for confirmation
before launching an attachment, just like you might appreciate a web
browser that shows the file type and asks for confirmation before
launching a downloaded file.
6) With the filename you gave, it shouldn't be that hard to find some
notes on this virus with google.
7) When the system is running away with background processes like you
describe, use the task manager to find out which process is using the
resources. Use this information in your research for a fix.

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: canvassing for assistance

2005-03-03 Thread Sean McIlroy
'scale' puts the lower-right corner of a bounding box where the
pointer is, while keeping the upper-left corner where it was before
(or, if the relevant item's coordinates aren't of bounding-box type,
the function does nothing).

Thanks for the link.

Peace,
STM


"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Sean, nice work on canvasser!  One question: what is the purpose of
> 'scale'?  I notice that if you have already drawn a line on the canvas,
> then 'scale' can be used to draw a straight-line element extending from
> the end of the previous freehand line, but if you start with a blank
> screen, 'scale' has no effect.
> 
> BTW if you want to extend your app further, take a look at paint.py in
> the Vaults of Parnassus:
> http://py.vaults.ca/apyllo.py?i=173784088
> 
> cheers,
> S
-- 
http://mail.python.org/mailman/listinfo/python-list


seeking tree-browser widget for use with Tkinter

2005-03-06 Thread Sean McIlroy
I'm looking for a widget, to be used with Tkinter, that displays a
tree whose leaves are strings. I thought there was something like that
in the Python Megawidgets, but when I look at the documentation
(http://pmw.sourceforge.net/doc/refindex.html), it doesn't seem to be
there. Any advice will be much appreciated.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs [was: function with a state]

2005-03-08 Thread Sean Blakey
On 8 Mar 2005 17:07:31 -0800, Xah Lee <[EMAIL PROTECTED]> wrote:
> thanks for the help...
> 
> ---
> the python doc is stilted. It tried to organized the thing and with a
> style around some highbrow inane "computer science" outlook.
> 
> i found the little section on global
> (http://python.org/doc/2.4/ref/global.html)
>  and can't make out what shit it is trying to say without having read
> and figured out the entire doc of its style and contexts and
> definitions. (formalization varies and computing model and jargons mean
> different things.)
> 
> Python doc writers needs to re-organize and re-style their docs so that
> its organization is towards programing, as opposed to how the
> implementation works (as in the Lib Reference), or a formalization of
> the language spec. (e.g. the fucking semi-joke of "(for language
> lawyers)" and BNF and those Runtime "Service" shits.) Its style
> needs to shift from highbrowism to pragmatic and exemplary.
> 
> I've addressed some of the jargon-riding ills common in industry with
> examples from the Python doc, archived here:
> http://xahlee.org/Periodic_dosage_dir/t2/xlali_skami_cukta.html
> 
> as to the way of its stiltedenss and academicism, which make it hard
> for programers to find or apply any info, i'll expound later.
> 
> PS just so that there is no misunderstanding: The docs of unix and
> Perl, are fucking criminally incompetent. Python docs, although stilted
> in a academic way, but nevertheless is solid, and its writers are
> educated, and tried best to make it a quality one, albeit sometimes
> inevitably showed some masterbation and jargonization. While the unix
> and Perl docs, (and essentially all things out of unix, e.g. Apache
> docs), are fucking incompetent drivels and in many cases exorbitant
> lies, and they semi-present it as humor and want and brainwash people
> to take them as norm. In a nutshell, these people are spreading
> untruths and indirectly are causing massive harm in the computing
> industry. People, we need to stop it. This each of us can do by not
> accepting their attitudes or behavior. In online forums, work place,
> conventions, conversations etc., raise questions or otherwise voice
> your opinion whenever you can.
> 
>  Xah
>  [EMAIL PROTECTED]
>  http://xahlee.org/PageTwo_dir/more.html
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Have you submitted a patch? I'm curious how you would document "global".

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Who Knows of a Good Computational Physics Textbook?

2005-03-13 Thread Sean Richards

This may be of interest

http://farside.ph.utexas.edu/teaching/329/lectures/lectures.html

Cheers,  Sean

-- 
"Hver sin smak", sa vintapperen, han drakk mens de andre sloss."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good use for Jython

2005-03-16 Thread Sean Blakey
On 15 Mar 2005 23:54:16 -0800, Mike Wimpe <[EMAIL PROTECTED]> wrote:
> Other than being used to wrap Java classes, what other real use is
> there for Jython being that Python has many other GUI toolkits
> available? Also, these toolkits like Tkinter are so much better for
> client usage (and faster) than Swing, so what would be the advantage
> for using Jython? or Is Jython really just so that Java developers can
> write Java code faster?
> 
> Mike Wimpe
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

I use an embedded Jython interpreter extensively for the business
logic layer of a Servlet/J2ee application. The back end uses,
Hibernate to connect to the database, so Jython's JavaBean
functionality is very useful for me, vastly simplifying and clarifying
my own logic.

As an added bonus, it is vastly easier to debug and redeploy a Jython
script file into a running system than it is to do the same with a
session EJB.

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


how to use structured markup tools

2005-03-19 Thread Sean McIlroy

I'm dealing with XML files in which there are lots of tags of the
following form: xy (all of these letters are being
used as 'metalinguistic variables') Not all of the tags in the file are
of that form, but that's the only type of tag I'm interested in. (For
the insatiably curious, I'm talking about a conversation log from MSN
Messenger.) What I need to do is to pull out all the x's and y's in a
form I can use. In other words, from...

.
.
x1y1
.
.
x2y2
.
.
x3y3
.
.

...I would like to produce, for example,...

[ (x1,y1), (x2,y2), (x3,y3) ]

Now, I'm aware that there are extensive libraries for dealing with
marked-up text, but here's the thing: I think I have a reasonable
understanding of python, but I use it in a lisplike way, and in
particular I only know the rudiments of how classes work. So here's
what I'm asking for:

Can anybody give me a rough idea how to come to grips with the problem
described above? Or even (dare to dream) example code? Any help will be
very much appreciated.

Peace,
STM

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


Re: how to use structured markup tools

2005-03-19 Thread Sean McIlroy
Exactly what I was looking for. Thanks.

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


tkinter manual question

2004-11-29 Thread Sean McIlroy
The 'Canvas Methods' section of the online Intro to Tkinter
(http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm)
refers (without explanation) to something called "bbox". What is this?
TIA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access to generator state

2004-12-02 Thread Sean Ross

"Neal D. Becker" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am converting optimization code from legacy C to python.  Generators are
a
> HUGE convenience, because the original code structures have the optimizer
> as the main code calling your function, while I want to invert these
roles.
> I want to call the optimizer to perform just one step at a time.
>
> So, the optimizer must preserve it's state.  The classic way to do this is
> with classes.  Problem is, I need to figure out just what variables need
to
> be preserved across calls.
>
> Using yield, this is trivial to achieve.  All state is automatically
saved.
>
> Only one problem.  Is there any way to access the state of a generator
> externally?  In other words, the generator saves all it's local variables.
> Can an unrelated object then query the values of those variables?  (In
this
> case, to get at intermediate results)
>


>>> def twice():
...  for i in range(0,2):
...   yield i
...
>>> gen = twice()
>>> gen.gi_frame.f_locals
{}
>>> gen.next()
0
>>> gen.gi_frame.f_locals
{'i': 0}
>>> gen.next()
1
>>> gen.gi_frame.f_locals
{'i': 1}
>>> gen.next()
Traceback (most recent call last):
  File "", line 1, in ?
StopIteration
>>>

HTH,
Sean


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


Re: question on regular expressions

2004-12-03 Thread Sean Ross
"Darren Dale" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm stuck. I'm trying to make this:
>
> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C
> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf
>
> (no linebreaks) look like this:
>
> ./mydoc1.pdf,./mydoc2.pdf
>
> my regular expression abilities are dismal. I won't list all the
> unsuccessful things I've tried, in a nutshell, the greedy operators are
> messing me up, truncating the output to ./mydoc2.pdf. Could someone offer
a
> suggestion?
>
> Thanks,
> Darren

from os.path import basename
import urllib

url = 'file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf'
print './%s'%basename(urllib.url2pathname(url))

HTH,
Sean



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


Re: Book Recommendations

2004-12-03 Thread Sean Dolan
Nathan Weston wrote:
I'm new to Python and am looking for a book to get me up to speed
quickly. I'm an experienced programmer and very proficient with Ruby,
so Python is coming easily to me and I don't need a gentle
introduction -- I just need a quick way to get familiar with common
Python idioms and important libraries.
http://www.diveintopython.org/
I'm also looking for a "gentler" book to help introduce some of my
co-workers to python. They are also experienced programmers, but
mostly in C++, with some Java/C# but minimal exposure to scripting
languages.
Any suggestions?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mean, median, and mode

2004-12-05 Thread Sean McIlroy
>>> mean = lambda x: sum(x)/len(x)
>>> median = lambda x: (max(x)-min(x))/2
>>> mode = lambda x: max([(x.count(y),y) for y in x])[1]

"Robert Brewer" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> (now that we have a meaningful subject line)
> 
> Alfred Canoy wrote:
> > >>  I'm just new to programming and would like to ask for help..
> > >>
> > >> Build a module that contains three functions that do the following:
> > >>
> > >>   a.. Compute the average of a list of numbers
> > >>   b.. Finds the statistical median value of a list of numbers
> > >>   c.. Finds the mode of a list of numbers
> > >>
> > >> Can you please give me clue how I should start solving the
> > >> following problem
> > >> below? Here's the source code that I did so far:
> > >>
> > >> # compute the average of a list of numbers:
> > >> # Keeps asking for numbers until 0 is entered
> > >> # Prints the average value
> > >>
> > >> count = 0
> > >> sum = 0
> > >> number = 1
> > >>
> > >> print 'Enter 0 to exit the loop'
> > >> while number != 0:
> > >> number = input ('Enter a number: ')
> > >> count = count + 1
> > >> sum = sum + number
> > >> count = count -1
> > >> print ' The average is:', sum/count
> 
> For the mode, you might build a dictionary:
> 
> freq = {}
> while number != 0:
> number = input ('Enter a number: ')
> count = count + 1
> sum = sum + number
> try:
> freq[number] += 1
> except KeyError:
> freq[number] = 1
> 
> ...then you can check for the largest value in that dictionary:
> 
> max = 0
> mode = None
> for k, v in freq.iteritems():
> if v > max:
> max = v
> mode = k
> 
> I leave the rest in your capable hands... ;) Including the case where
> two numbers occur in equal frequencies. ;;)
> 
> 
> Robert Brewer
> MIS
> Amor Ministries
> [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Find index of item in list

2004-12-07 Thread Sean Berry
Given

myList = ['cat', 'dog', 'mouse' ... 'bear']

what is the easiest way to find out what index 'dog' is at?



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


example code sought

2004-12-18 Thread Sean McIlroy
There's something quite simple I'd like to do, but I'm hampered by
lack of knowledge regarding Tkinter. If someone could help me out with
a snippet of maximally-simple code showing, in general terms, how to
do this, that would be really great. What I want to do is simply to
move a shape around on the screen using the mouse. I've looked at
Tkdnd.py but I can't seem to extract what I need from the more
involved stuff in there.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython performance

2004-12-22 Thread Sean Blakey
On Wed, 22 Dec 2004 17:03:55 -0200, Gabriel Cosentino de Barros
<[EMAIL PROTECTED]> wrote:
>  
> 
> On the "Best GUI for small-scale accounting app?" tread some people
> mentioned jython. I went to read about it, but i was wondering if anyone has
> any real project done with it and can give real world comments about
> performance. 
> 
> Thanks, 
> Gabriel 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

I've been very happy with it's performance, after the one-time
interpreter startup. Currently, I am using Jython embedded in a large
Web Application, with Struts actions defined in Jython working with
Java Beans managed by a Hibernate back end. The Jython-beans
interoperability makes this very simple, and I'm not seeing an
appreciable performance difference between the Jython actions and the
pure Java actions.


-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


cosmetic Tkinter question

2004-12-26 Thread Sean McIlroy
I've got a bunch of Frames, all packed into the root window with
side=TOP, and in each Frame I've got a Checkbutton packed with
side=LEFT. I expected the Checkbuttons to be flush with the left edge
of the window, but they're not, and it looks a little gross. How do I
get them to align?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: built-in 'property'

2004-12-30 Thread Sean Ross
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
[snip]
> For this reason, I usually suggest declaring properties like[1]:
>
> py> class E(object):
> ... def x():
> ... def get(self):
> ... return float(self._x)
> ... def set(self, x):
> ... self._x = x**2
> ... return dict(fget=get, fset=set)
> ... x = property(**x())
> ... def __init__(self, x):
> ... self._x = x
> ...
[snip]
>
> [1] Thanks to whoever originally suggested this! Sorry, I've forgotten
> who...

Hello.

As Alex mentioned, I'm the author of the "tidy property idiom" recipe. I
stumbled across the idea back in June of 2003, when there were ongoing
discussions about property syntax and, in particular, thunks. I've
discovered that Greg Ewing had a similar idea 6 months earlier [1], though I
wasn't aware of that at the time. I'll note that it is possible to change
the built-in property (in a backward compatible manner) to be used as a
decorator for this idiom, to redefine parts of properties in sub-classes,
and to provide default get/set/del methods. That being said, while I
appreciate that there are people who like this recipe (and others who
don't), I think it's important to point out that this is *not* the
recommended property idiom. Moreover, Guido doesn't like it and he would
prefer that it not become the standard [2][3].

Sean


[1] http://mail.python.org/pipermail/python-dev/2003-January/032611.html
[2] http://mail.python.org/pipermail/python-dev/2003-January/032630.html
[3] http://mail.python.org/pipermail/python-dev/2004-January/042206.html


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


mysteriously nonfunctioning script - very simple

2005-03-25 Thread Sean McIlroy
Can anybody help me make sense of the fact that the following script
doesn't work? It's so simple I can't imagine what I'm missing. Any
help will be much appreciated.

Peace,
STM


## ALARM CLOCK:
from time import sleep,time,localtime

wakeuptime = input('hours: '), input('minutes: ')
onehourlater = (wakeuptime[0]+1, wakeuptime[1])
while not wakeuptime < localtime(time())[3:5] < onehourlater:
sleep(3)
print 'PLAY A SOUND FILE'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mysteriously nonfunctioning script - very simple

2005-03-26 Thread Sean McIlroy
Fair enough. Here's the verbose version:

##
from time import sleep,time,localtime

wakeuptime = (7,00) 
## I WANT TO BE WOKEN UP AT 7AM (FOR EXAMPLE)

onehourlater = (wakeuptime[0]+1, wakeuptime[1]) 
## ONE HOUR LATER THAN THAT IS 8AM

while not wakeuptime < localtime(time())[3:5] < onehourlater: sleep(3)
## CHECK THE CURRENT TIME EVERY 3 SECONDS, AND IF IT'S NOT BETWEEN
## 7AM AND 8AM, GO BACK TO SLEEP FOR ANOTHER 3 SECONDS

## CONTROL NEVER REACHES THIS POINT
##










Peter Hansen <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Sean McIlroy wrote:
> > Can anybody help me make sense of the fact that the following script
> > doesn't work? It's so simple I can't imagine what I'm missing. Any
> > help will be much appreciated.
> 
> Always post actual tracebacks of the problem, if
> indeed it is producing a traceback.  Do this always
> by *cut and paste*, not by retyping the text.  Make
> sure not to remove anything important, and make sure
> you are running the actual code you have posted here.
> 
> Also always describe the problem in more detail than
> just "doesn't work".  For all we know, the code runs
> fine but its output just doesn't suit you...
> 
> -Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mysteriously nonfunctioning script - very simple

2005-03-27 Thread Sean McIlroy
Heiko Wundram <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...


> Why not try the following:


I did try it, and it didn't work either. It appears there must be
something wrong with my computer, hopefully something benign. Thanks
anyway.

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2005-03-28 Thread Sean Blakey
On 28 Mar 2005 15:00:37 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello,
> 
> How do i create two memory mapped buffers(mmap) and pass an index to
> select which one needs to be populated?
> 
> Is it possible to define the size of the buffer?
> 
> -SB
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

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

I haven't tried it, but it should be pretty straightforward to create
two mmaped buffers.

Step 1: Import the mmap module.

Step 2: Create or find the file you want to map. Open it, and get the
fileno. Call mmap.mmap, passing the fileno and buffer size.

Repeat Step 2 with a different file to create a second mmaped buffer.

I'm not sure what you mean by "and pass an index to select which one
needs to be populated". If you pack the buffers into a
tuple/list/other sequence object, it should be easy to access them by
index:

>>> buffers = (buffer_1, buffer_2)
>>> do_something_to(buffers[0])
>>> do_something_else_with(buffers[1])

To mmap buffers, you MUST define the size.

I'm sorry I can't be more helpful; perhaps if you gave a higher-level
description of what you are trying to accomplish, I could give better
pointers in the right direction.

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doing "checksum" in python

2005-03-28 Thread Sean Blakey
On 28 Mar 2005 15:11:32 -0800, GujuBoy <[EMAIL PROTECTED]> wrote:
> is there a built-in function that does a "checksum" on a file...basicly
> counts the bytes and computes a 16-bit checksum for each given FILE.
> 
> this is the like the "sum" command in unix
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Not built-in, but you can find a few implementations with a quick
google search for "python 16-bit checksum":
http://mail.python.org/pipermail/python-list/2001-May/042691.html
http://mail.python.org/pipermail/python-list/2004-January/204983.html
http://mail.python.org/pipermail/python-list/2004-January/204998.html

-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


IMAP4.search by message-id ?

2005-03-29 Thread Sean Dodsworth
Can anyone tell me how to get a message's number from the message-id 
using IMAP4.search?
I've tried this:
resp, items = server.search(None, 'HEADER', '"Message-id"', msgID)
but it gives me a 'bogus search criteria' error

Any ideas?


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


Re: IMAP4.search by message-id ?

2005-03-30 Thread Sean Dodsworth
Max M wrote:

> Sean Dodsworth wrote:
>> Can anyone tell me how to get a message's number from the message-id
>> using IMAP4.search?
>> I've tried this:
>> resp, items = server.search(None, 'HEADER', '"Message-id"', msgID)
>> but it gives me a 'bogus search criteria' error
> 
> 
> Why do you need the 'HEADER'
> 
> Wouldn't this be enough?
> 
> resp, items = server.search(None, 'Message-id', msgID)
> 
> I am note shure if the msgId should be quoted. I assume not, as it will
> allways be an integer.
> 

Max,
Thanks, but it didnt work.
I still get the same error:
error: SEARCH command error: BAD ['Bogus criteria list in SEARCH']
args = ("SEARCH command error: BAD ['Bogus criteria list in SEARCH']",)

I had originally included the HEADER field as per the RFC3501 documentation:
HEADER  

also, the message-id is not an integer its a string like:
<[EMAIL PROTECTED]>

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


Re: initialize a dictionary

2005-03-30 Thread Sean Blakey
On 30 Mar 2005 13:02:05 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello,
> 
> Can I do something like this?
> 
> table = {}
> table[32, 16] = 0x0
> 
> Where 32 specifies rows and 16 specifies columns and i am trying to
> initialize it to zero
> 
> I should be able to do comparisons like:
> table[t1, t2] == 0x1 etc.
> -SB
> 

Try it. It works. Sort of.

This code actually creates a dict named "table" mapping the key tuple
(32, 16) to the value 0x0. Note that you are NOT creating a
two-dimensional array, so this approach may be problematic if you ever
need to iterate values "by row" or "by column".

There is a python F.A.Q. on this, which you may find useful:
http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list



-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: IMAP4.search by message-id ?

2005-03-31 Thread Sean Dodsworth
Tony Meyer wrote:

>> Can anyone tell me how to get a message's number from the message-id
>> using IMAP4.search?
>> I've tried this:
>> resp, items = server.search(None, 'HEADER',
>> '"Message-id"', msgID) but it gives me a 'bogus search criteria' error
> 
 import imaplib
 i = imaplib.IMAP4("mail.example.com")
 i.login("username", "password")
> [...]
 i.select()
> [...]
 i.search(None, '(HEADER Message-ID
> "<[EMAIL PROTECTED]>")')
> ('OK', ['4'])
 i.logout()
> [...]
> 
> =Tony.Meyer

Thank Tony...works fine now
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ternary Operator in Python

2005-04-01 Thread Sean Kemplay
You could use 

condition and consequent or alternative

I use it
Sean

On Apr 1, 2005 5:24 PM, praba kar <[EMAIL PROTECTED]> wrote:
> Dear All,
> I am new to Python.  I want to know how to
> work with ternary operator in Python.  I cannot
> find any ternary operator in Python.  So Kindly
> clear my doubt regarding this
> 
> 
> __
> Yahoo! Messenger
> Show us what our next emoticon should look like. Join the fun.
> http://www.advision.webevents.yahoo.com/emoticontest
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ternary Operator in Python

2005-04-01 Thread Sean Kemplay
On Apr 1, 2005 8:10 PM, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> Sean Kemplay wrote:
> 
> > You could use
> >
> > condition and consequent or alternative
> >
> > I use it
> 
> You should do so cautiously, since if consequent is false, it will not
> behave as suspected.  Not to mention that it's quite unreadable.
> 
> --
> Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
> San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
>Physics, as we know it, will be over in six months.
>-- Max Born (1928)
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

I should have mentioned that, as I have been caught out before.

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


the bugs that try men's souls

2005-04-03 Thread Sean McIlroy
This needs some background so bear with me.

The problem: Suppose p is a permutation on {0...n} and t is the
transposition that switches x and y [x,y in {0...n}]. A "stepup pair"
(just a term I invented) for p is a pair (a,b) of integers in {0...n}
with a>
k = 18
moved = [i for i in range(len(t)) if t[i]<>i]
a, b = min(moved), max(moved)
n = len(p) - 1
s = stepups(n) ## MYSTERIOUSLY BROKEN: [x for x in stepups(n) if
xor(a in x,b in x)]
print '-'*k
print 'p: ' + str(range(n+1)) + '\n   ' + str(p)
print '-'*k
print 't = ' + str((a,b))
print '-'*k
print '%s %7s %3s' %('pair','p','pt') + '\n' + '-'*k
for [a,b] in s:
print '%s %5s %3s' %(str([a,b]),int([p[a],p[b]] in
s),int([p[t[a]],p[t[b]]] in s))
print '-'*k

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


Re: the bugs that try men's souls

2005-04-03 Thread Sean McIlroy
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...



Wow. I'd resigned myself to the task of reformulating my question in
an intelligent way, I stopped by just to leave a little note to the
effect that the thread wasn't dead, and I find out the question's been
answered. Thanks very much. I'll let you know how it turns out.

Peace,
Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the bugs that try men's souls

2005-04-03 Thread Sean McIlroy

Wow again. I had a real "V8 moment" when I looked at your solution
(smacking my forhead, groaning ruefully, etc). You were right: my
intention was simply to hide the trivial cases from view; I completely
missed the fact that I was now testing for membership in a different
set. I should have remembered that python "plays fair", and looked a
little harder to find my mistake.

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


Re: within a class, redefining self with pickled file

2005-04-07 Thread Sean Blakey
On 7 Apr 2005 15:27:06 -0700, syd <[EMAIL PROTECTED]> wrote:
> def unpickle(self):
>   self = pickle.load(open(self.getFilePath('pickle')))
> 
> This evidently does not work.  Any idea why?  I'd like to be able to
> replace a lightly populated class (enough to identify the pickled
> version correctly) with it's full version that's sitting pickled in a
> file.
> 
> As of right now, I need to just return self and redefine the class.
> 
> Thanks!
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

This problem has nothing to do with pickling. In general, assigning to
a parameter (even self) will not make a change that lasts after the
method call. For example:

>>> class A:
... def change(self):
... self = "something else entirely"
...
>>> a = A()
>>> a.change()
>>> a
<__main__.A instance at 0x009DCD00>

Note, however, that you can MODIFY self in-place within a method. You
can probably hack together a solution that modifies self.__dict__,
self.__class__, self.__class__.__dict__, or some other magic
properties.
-- 
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
-- 
http://mail.python.org/mailman/listinfo/python-list


Debugging on the Mac question.

2014-01-03 Thread Sean Murphy
Team,


I am a Vision Impaired programmer on the Mac and Window platforms. I have 
started to learn Python. The biggest road block I have is the ability of 
debugging my simple scripts. The IDLE program does not work with the screen 
readers I use on the Mac or Windows. A screen reader is a program that grabs 
the text on the screen and converts it into speech output, at least this is the 
5 feet explanation.  I cannot see the screen at all.

I have looked at eclipse and it doesn't work with Voice-Over (the screen reader 
on the Mac). I have java issues on my windows machine preventing me running 
this app.

If I use $python -d script.py the debugger doesn't seem to trigger on the mac. 

So how I can perform a debug on a script so I can step through it, set up break 
points, watch variables, etc. 

It is really annoying me, since under Perl I just added the -d switch and had a 
full debugger that worked at the console level.

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


Re: Debugging on the Mac question.

2014-01-03 Thread Sean Murphy
PETER,

thanks Peter, I have already found the PDB module and have had a play with it. 
It will do for now.
On 03/01/2014, at 8:08 PM, Paul Rudin  wrote:

> Sean Murphy  writes:
> 
> 
>> I am a Vision Impaired programmer on the Mac and Window platforms. I have
>> started to learn Python. The biggest road block I have is the ability of
>> debugging my simple scripts. The IDLE program does not work with the screen
>> readers I use on the Mac or Windows. A screen reader is a program that grabs
>> the text on the screen and converts it into speech output, at least this is 
>> the
>> 5 feet explanation.  I cannot see the screen at all.
>> 
>> I have looked at eclipse and it doesn't work with Voice-Over (the screen 
>> reader
>> on the Mac). I have java issues on my windows machine preventing me running
>> this app.
>> 
>> If I use $python -d script.py the debugger doesn't seem to trigger on the 
>> mac. 
>> 
>> So how I can perform a debug on a script so I can step through it, set up 
>> break
>> points, watch variables, etc.
>> 
>> It is really annoying me, since under Perl I just added the -d switch and 
>> had a
>> full debugger that worked at the console level.
> 
> For command line debugging see
> <http://docs.python.org/3/library/pdb.html>. 
> 
> 
> More generally you might want to investigate
> <http://emacspeak.sourceforge.net/> (disclaimer - I have never used
> this, but from what you say you might find it useful).
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


  1   2   3   4   5   >