Jabber Bot

2013-07-18 Thread Matt
Anyone have any luck with creating Jabber Bots?

Everyone I have found so far for python 3.3 has been outdated, or the required 
modules are outdated.
-- 
http://mail.python.org/mailman/listinfo/python-list


What do you do when a library is outdated?

2013-07-29 Thread Matt
I'm fairly new to python but have experience in other languages. What do you 
generally do when a library is outdated? I asked a question on a few forums and 
everyone has been pointing me to Mechanize, but it will not work with 3.3 

What do you do? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What do you do when a library is outdated?

2013-07-29 Thread Matt
On Monday, July 29, 2013 12:34:08 PM UTC-4, Chris Angelico wrote:
> On Mon, Jul 29, 2013 at 5:14 PM, Matt  wrote:
> 
> > I'm fairly new to python but have experience in other languages. What do 
> > you generally do when a library is outdated? I asked a question on a few 
> > forums and everyone has been pointing me to Mechanize, but it will not work 
> > with 3.3
> 
> >
> 
> > What do you do?
> 
> 
> 
> Depends what you mean by "outdated". Lots of things don't _need_ to be
> 
> up-to-date to be useful, and often, using the very latest version of
> 
> something just makes it hard to deploy (look at Debian and Red Hat,
> 
> both of which maintain support for a long time). If there's actually a
> 
> problem with something not being able to cope with current systems (eg
> 
> something that's designed to communicate with Windows and can't talk
> 
> to Win 8), then you go looking for a replacement package that can use
> 
> the latest, or possibly you write it yourself.
> 
> 
> 
> But my crystal ball tells me you're not asking about that, but rather
> 
> about a module that was written for Python 2 and hasn't been ported to
> 
> Python 3. (Usually there won't be other issues; if something breaks
> 
> between Py3.2 and Py3.3, it'll be easily fixed.) There are a few
> 
> options:
> 
> 
> 
> 1) Talk to the author/maintainer. Explain that you want to use his/her
> 
> code with Python 3 but can't. Often, the only reason something isn't
> 
> ported is because of a perceived lack of interest.
> 
> 2) Run the module code through the 2to3 utility. That might even be
> 
> all you need to do.
> 
> 3) Port it yourself. Start with 2to3, and then work through any
> 
> problems you have. I would recommend getting to know the module on
> 
> Python 2 first, so you have a chance of knowing what it ought to be
> 
> doing.
> 
> 
> 
> You aren't the first to inquire about this. A quick Google search for
> 
> 'mechanize python 3' brought this up:
> 
> http://web.cecs.pdx.edu/~adevore/mechanize/
> 
> 
> 
> Also, poking around a bit shows recommendations for the lxml and
> 
> requests modules, which may be able to do what you want.
> 
> 
> 
> So to answer your general question: Work, sometimes lots of work
> 
> (though not always). But for Mechanize specifically, Requests may be
> 
> your best bet.
> 
> 
> 
> ChrisA

I appreciate this. I did not know of 2to3, and I am going to give that a shot 
right now. Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


question about importing a package

2012-12-05 Thread Matt
I have a directory structure that looks like this:

sample.py
sub_one/
  __init__.py # defines only the list__all__ = ['foo', 'bar']
  foo.py   # defines the function in_foo()  
  bar.py   # defines the function in_bar()

In sample.py, I have this command at the top:

from sub_one import *

I can't refer to in_foo() and in_bar() without prefacing them with the module 
names. I.e. foo.in_foo() and bar.in_bar() work, but I want to import them in 
the __main__ namespace of sample.py and refer to them as just in_foo() and 
in_bar(). I know this is frowned upon, but for my purposes it is the best 
choice. I have about 30 modules in my package (foos and bars) and I don't want 
30 lines at the top of each file that uses this package. What am I doing wrong?

Thanks,

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


Re: question about importing a package

2012-12-06 Thread Matt
It works now. Steven and Alex, thanks for your help!

I ended up leaving sample.py and foo.py and bar.p the way they were, and in 
__init__.py putting:

from foo import *
from bar import *

So my mistake was not importing the foo and bar modules into 
sub_one/__init__.py.

I also see how the __all__ array helps me control what gets imported. I can 
leave it out of __init__.py, and everything gets imported. So my three lessons 
are:

1) "from X import *" will look for an __all__ list in module X, or in 
__init__.py if X is a package instead of a module, and import only what is in 
that list. Module names are different than function names in that list.
2) if __all__ is not defined, "from X import *' will import everything in X's 
namespace
3) __init__.py acts like just another module, so you have to import the package 
contents that you want into it before you import the package into your code

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


Threading

2020-01-24 Thread Matt
I am using this example for threading in Python:

from threading import Thread

def start_test( address, port ):
print address, port
sleep(1)

for line in big_list:
t = Thread(target=start_test, args=(line, 80))
t.start()

But say big_list has thousands of items and I only want to have a
maximum of 10 threads open.  How do work my way through the big_list
with only 10 threads for example?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading

2020-01-24 Thread Matt
So I would create 10 threads.  And each would pop items off list like so?


def start_test():
while big_list:
list_item = big_list.pop()
print list_item, port
sleep(1)

port = 80
for i = 1 to 10
t = Thread(target=start_test)
t.start()

t.join()



Would that be thread safe?

On Fri, Jan 24, 2020 at 2:44 PM Chris Angelico  wrote:
>
> On Sat, Jan 25, 2020 at 7:35 AM Matt  wrote:
> >
> > I am using this example for threading in Python:
> >
> > from threading import Thread
> >
> > def start_test( address, port ):
> > print address, port
> > sleep(1)
> >
> > for line in big_list:
> > t = Thread(target=start_test, args=(line, 80))
> > t.start()
> >
> > But say big_list has thousands of items and I only want to have a
> > maximum of 10 threads open.  How do work my way through the big_list
> > with only 10 threads for example?
>
> First off, it is high time you move to Python 3, as the older versions
> of Python have reached end-of-life.
>
> The best way is to create your ten threads, and have each one request
> "jobs" (for whatever definition of job you have) from a queue. Once
> the queue is exhausted, the threads terminate cleanly, and then you
> can join() each thread to wait for the entire queue to be completed.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading

2020-01-24 Thread Matt
Created this example and it runs.

import time
import threading

big_list = []

for i in range(1, 200):
big_list.append(i)

def start_test():
while big_list: #is this
list_item = big_list.pop() #and this thread safe
print list_item, port
time.sleep(1)

print "Creating Threads..."

port = 80
for i in range(1, 10):
t = threading.Thread(target=start_test)
t.start()

print "Waiting on Threads..."

t.join()

print "Finished..."

On Fri, Jan 24, 2020 at 2:44 PM Chris Angelico  wrote:
>
> On Sat, Jan 25, 2020 at 7:35 AM Matt  wrote:
> >
> > I am using this example for threading in Python:
> >
> > from threading import Thread
> >
> > def start_test( address, port ):
> > print address, port
> > sleep(1)
> >
> > for line in big_list:
> > t = Thread(target=start_test, args=(line, 80))
> > t.start()
> >
> > But say big_list has thousands of items and I only want to have a
> > maximum of 10 threads open.  How do work my way through the big_list
> > with only 10 threads for example?
>
> First off, it is high time you move to Python 3, as the older versions
> of Python have reached end-of-life.
>
> The best way is to create your ten threads, and have each one request
> "jobs" (for whatever definition of job you have) from a queue. Once
> the queue is exhausted, the threads terminate cleanly, and then you
> can join() each thread to wait for the entire queue to be completed.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading

2020-01-24 Thread Matt
>  Not quite.
>
> 1. Create a list of threads.
>
> 2. Put the items into a _queue_, not a list.
>
> 3. Start the threads.
>
> 4. Iterate over the list of threads, using .join() on each.
>
> If you're going to start the threads before you've put all of the items
> into the queue, you can also put a sentinel such as None into the queue
> after you've finished putting the items into it. When a thread sees the
> sentinel, it knows there are no more items to come. You could have one
> sentinel for each thread, or have only one and have each thread put it
> back when it sees it, for the other threads to see.
>


Is the list not thread safe and I need to use Queue instead or is it
just that using a Queue is more efficient?  I think I have everything
else you mentioned changed. Even in python3 now though I still need to
work in python2 in places for time being. Thanks.

import time
import datetime
import threading
import random

big_list = []

def date_stamp():
return "[" + datetime.datetime.now().strftime('%Y-%m-%d
%H:%M:%S:%f')[:-3] + "] "

for i in range(1, 5000):
big_list.append(i)

def start_test(id):
while big_list:
list_item = big_list.pop()
print(date_stamp(), "Thread", id, ":", list_item, port)
time.sleep(random.random())
print(date_stamp(), "Thread", id, "done...")

print(date_stamp(), "Creating Threads...")

port = 80
threads = []
for i in range(1, 10):
t = threading.Thread(target=start_test, args=(i,))
print(date_stamp(), "Starting Thread:", i)
t.start()
threads.append(t)

print(date_stamp(), "Waiting on Threads...")

for t in threads:
t.join()

print(date_stamp(), "Finished...")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread Matt
Xah Lee wrote:
>There are quite a lot f___ing liers and charlatans in the computing
>industry, especially the OpenSourcers, from the f___ing
>a-dime-a-million students with their "FREE" irresponsible homeworks
>on the net to f___heads like James Gosling of Java , Larry Wall of
>Perl, Linus Torvolts of Linux kernel, and that f___head C++ Berjo
>something, the unix advocating f___ers, and those "gang of four"
>Design Patterns shit and the criminals of eXtreme Programing and UML...
>with these pundits begets one generation of f___ing tech geeking coding
>monkeys, thinking that they know something, while creating a mass of
>garbage that crashes and f___s us up everyday in the computing world.

OK... your post seems to indicate a belief that everyone else is
somehow incompetent. Sounds a bit like the "I am sane, it is everyone
else who is crazy" concept. Can you suggest a technology or
technologist who, in your expert opinion, has gotten it right?

Perhaps the language you have developed and others are using
successfully fits all of our needs?

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


pyzeroconf on linux...

2005-11-02 Thread matt
Hey, has anyone out there tried pyzeroconf on Linux?  I'm using
Andrew's code from http://www.amk.ca/python/zeroconf to publish and
discover services.  The code works under Mac.  But it doesn't under
linux (FC4).

I should clarify that, it appears that the publish code doesn't work
under linux.  The discovery code will discover stuff (on linux) that I
publish on the Mac.  I've fired up ethereal and it doesn't appear that
much is happening in the way of UDP on port 5353 (on linux).

Does anyone have any hints or suggestions?

thanks

matt

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


Re: pyzeroconf on linux...

2005-11-02 Thread matt
Another (easier) example of it failing, is to just run "python
Zeroconf.py":
1. Testing registration of a service...
   Registering service...
   Registration done.
2. Testing query of service information...
   Getting ZOE service: None
   Query done.
3. Testing query of own service...
   Getting self: None
   Query done.
4. Testing unregister of service information...
   Unregister done.

On the Mac section 3. actually returns something other than "None" (ie
service[My Service Name._http._tcp.local.,127.0.0.1:1234, a=test value
ver ...] ).

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


Re: question about urllib and parsing a page

2005-11-02 Thread matt
Yeah, this tends to be silly, but a workaround (for firefox at least)
is to select the content and rather than saying view source, right
click and click View Selection Source...

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


Re: pyzeroconf on linux...

2005-11-02 Thread matt
I think I've figured it out.  It appears to be a misconfiguration on my
part.  In my /etc/hosts file I had the loopback address pointing to my
machine name.  I made 127.0.0.1  only point to localhost and I can now
publish services!

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


pyzeroconf on windows

2005-11-02 Thread matt
Since I'm on the topic of pyzeroconf today, I might as well keep
posting ;)
So on to another platform... windows.  Has anyone used pyzeroconf on
Windows recently?  It doesn't appear to work (and it isn't the
127.0.0.1 thing either).

Running python Zeroconf.py gives the following:
Multicast DNS Service Discovery for Python, version 0.12
1. Testing registration of a service...
   Registering service...
   Registration done.
2. Testing query of service information...
   Getting ZOE service: None
   Query done.
3. Testing query of own service...
   Getting self: None
   Query done.
4. Testing unregister of service information...
   Unregister done.
Traceback (most recent call last):
  File "Zeroconf.py", line 863, in run
self.readers[socket].handle_read()
  File "Zeroconf.py", line 906, in handle_read
data, (addr, port) =
self.zeroconf.socket.recvfrom(_MAX_MSG_ABSOLUTE)
  File "C:\Python23\lib\socket.py", line 143, in _dummy
raise error(EBADF, 'Bad file descriptor')
error: (9, 'Bad file descriptor')


Also, note that besides the error, the query of "own service" (#3
above) also failed to detect anything.

Anyone have any clues?
Thought I'd ask before delving into sockets on windows

thanks
matt

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


Re: Contest snub?

2005-11-03 Thread Matt
Updated: http://www.apress.com/promo/fractal/result.html

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


Re: best way to discover this process's current memory usage, cross-platform?

2005-11-15 Thread matt
Perhaps you could extend Valgrind (http://www.valgrind.org) so it works
with python C extensions?  (x86 only)

matt

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


Newbie question. Pyexpat fails on make

2005-11-18 Thread Matt
Hi

I want to build pyexpat and link it statically in Python. Im using
Python 2.4.2. This is just a straight forward build using ./configure
and then make

I change *shared* to *static* and then uncoment these two lines:

EXPAT_DIR=/usr/local/src/expat-1.95.2
pyexpat pyexpat.c -DHAVE_EXPAT_H -I$(EXPAT_DIR)/lib -L$(EXPAT_DIR) -lexpat

The directory /usr/local/src/expat-1.95.2 doesn't exist so I assume I
need to change it to the expat dir. One question will the libexpat.a
library be built and is this the one refered to -lexpat?

Modules/pyexpat.c: In function `call_with_frame':
Modules/pyexpat.c:387: warning: implicit declaration of function
`XML_StopParser'
Modules/pyexpat.c:387: error: `XML_FALSE' undeclared (first use in this
function)
Modules/pyexpat.c:387: error: (Each undeclared identifier is reported
only once
Modules/pyexpat.c:387: error: for each function it appears in.)
Modules/pyexpat.c: In function `my_ElementDeclHandler':
Modules/pyexpat.c:777: warning: implicit declaration of function
`XML_FreeContentModel'
Modules/pyexpat.c: In function `initpyexpat':
Modules/pyexpat.c:1966: error: `XML_ERROR_ENTITY_DECLARED_IN_PE'
undeclared (first use in this function)
Modules/pyexpat.c:1967: error: `XML_ERROR_FEATURE_REQUIRES_XML_DTD'
undeclared (first use in this function)
Modules/pyexpat.c:1968: error:
`XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING' undeclared (first use in
this function)
Modules/pyexpat.c:1970: error: `XML_ERROR_UNBOUND_PREFIX' undeclared
(first use in this function)
Modules/pyexpat.c:1972: error: `XML_ERROR_UNDECLARING_PREFIX' undeclared
(first use in this function)
Modules/pyexpat.c:1973: error: `XML_ERROR_INCOMPLETE_PE' undeclared
(first use in this function)
Modules/pyexpat.c:1974: error: `XML_ERROR_XML_DECL' undeclared (first
use in this function)
Modules/pyexpat.c:1975: error: `XML_ERROR_TEXT_DECL' undeclared (first
use in this function)
Modules/pyexpat.c:1976: error: `XML_ERROR_PUBLICID' undeclared (first
use in this function)
Modules/pyexpat.c:1977: error: `XML_ERROR_SUSPENDED' undeclared (first
use in this function)
Modules/pyexpat.c:1978: error: `XML_ERROR_NOT_SUSPENDED' undeclared
(first use in this function)
Modules/pyexpat.c:1979: error: `XML_ERROR_ABORTED' undeclared (first use
in this function)
Modules/pyexpat.c:1980: error: `XML_ERROR_FINISHED' undeclared (first
use in this function)
Modules/pyexpat.c:1981: error: `XML_ERROR_SUSPEND_PE' undeclared (first
use in this function)
make: *** [Modules/pyexpat.o] Error 1

Im sure this is something stupid im doing. Assistance apprecited

Cheers

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


Re: Los Angeles Python Users' Group, anyone?

2005-11-18 Thread Matt

[EMAIL PROTECTED] wrote:
> Hi,
>
> I was rifling through python.org to see if there was an existing Python
> user's group for the Los Angeles area. Doesn't seem like it, so maybe
> we should start one? I'm interested in helping with the coordination of
> activities etc.
>
> Since everybody living in greater L.A. area is likely to have
> superhuman tolerance for traffic and commuting times, I see no reason
> why an L.A users' group couldn't cover the whole
> LA/Valley/Burbank/Glendale/Pasadena/Long Beach/etc sprawl.
>
> Anyone interested, please email me at: m AT bagai DOT com
>
> Thanks!
>
> /Morten

There is a SoCal python users' group:
http://lists.idyll.org/listinfo/socal-piggies
They meet in the Los Angeles area.

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


Re: Newbie question - clearing screen @ interactive prompt

2005-12-09 Thread matt
Just press Control-L.

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


Re: Raw Sockets vs. What?

2005-01-07 Thread Matt
Just thought I'd follow up to say that I'm using XML-RPC after all. Not
that I was intimidated when I finally learned that Fredrik had written
the thing. No, it was more the issue that we want to write a php
debugger next and XML-RPC plays well with php, too.
Thanks again,
--Matt

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


Re: Configuring Python for Tk on Mac

2005-01-21 Thread Matt
I googled around and it looks like it might be a permissions error:
http://mail.python.org/pipermail/pythonmac-sig/2002-November/006809.html
I don't have a Mac, tho', so I have no idea if it works...
HTH

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


Re: Help With Python

2005-01-26 Thread Matt
Nick Vargish wrote:
> Here's my Monty Pythonic answer:
>
> ## cut here
> class Viking():
>
> def __init__():
> pass
>
> def order():
> return 'Spam'
>
> # this is one viking making one order repeated 511 times. if you want
> # 511 vikings making seperate orders, you'll have to write a loop.
> v = Viking()
> orders = [ v.order() ] * 511
>
> print ', '.join(orders)
> ## cut here
>
> With no apologies to Eric Idle,
>
> Nick
>
>
> --
> #  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this
to a python
> print reduce(lambda x,y:x+chr(ord(y)-1),'
Ojdl!Wbshjti!=obwAcboefstobudi/psh?')

Not to be nit-picky, but you got some issues here ;-).  Never forget
the importance of "self"!

###
class Viking:
.   def __init__(self):
.   pass
.   def sing(self):
.   return 'Spam'
v = Viking()
spam_song = [ v.sing() ] * 511
print ', '.join(spam_song)

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


Re: newbie: Syntax error

2005-02-04 Thread Matt

Chad Everett wrote:
> Hi Everyone,
>
> I am new to Python and programming in general.  I bought the book
"Python
> Programming for the Absolute Beginner" by michael Dawson.
>
> I have been working through it but am having trouble.
> I am trying to make a coin flip program and keep geting a Synax Error
> "invalid syntax".
>
> If anyone has a moment could you please look at it and tell me what I
am
> doing wrong.
>
> thanks for your time and patience.
>
> Chad
>
> # Coin Flip Program
> # This program flips a coin 100 times and tells the number of heads
and
> tails.
> # Chad Everett 2/3/2005
>
>
> print "\t\tCoin Flip Game*\n"
> import random
>
> # heads = 1
> # tails = 2
>
> tries = random.randrange(2) + 1
> count = 1
>
> while count != 100:
> if tries == 1:
> heads = 1
> count += 1
>
> else tries == 2:  # I AM GETTING THE SYNTAX ERROR HERE
> tails = 1
> count += 1
>
> print "heads: " + heads
> print "tails: " + tails
>
> raw_input("Press enter to quit")

Chad,

The problem is that you have the statement "tries == 2" after "else".
The proper syntax is:
> elif tries == 2:  # note "elif"
> tails = 1
> count += 1

Here's an example of if/elif/else statements in Python:
http://www.network-theory.co.uk/docs/pytut/tut_21.html

Enjoy learning!

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


Re: python parser

2005-07-12 Thread matt
I recently was successful using pyparsing after messing around with ply
for a few hours.  See my blog for more details (
http://panela.blog-city.com/icfp_contest_implementation_in_python_notes.htm
).

I personally corresponded with the author and he was very helpful as
well, giving my useful critiques and feedback.  The next time I'm
parsing something more complex than a tab-delimited file (excluding xml
:)) I'll probably use pyparsing.  I found it very pythonic and easy to
use.

good luck parsing...
matt

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


How to create "cross-backend" python web app

2005-07-14 Thread matt
Hi all-

I'm trying to port an ajax spell-checker
(http://www.broken-notebook.com/spell_checker/index.php) to use with
the moin moin wiki and have been somewhat successful.  (By successful I
mean I can spell check using the php backend and my python port running
as cgi-bin).

My question is this:  moinmoin runs on many python web backends
(cgi-bin/mod-python/twisted/standalone).  My spell-checker backend runs
as cgi (disclaimer: I've done a bit of php and java(struts) web app
programming, but the last python related web programming I did was Zope
about 5 years ago (does that even count ? ;) )) because that was the
easiest for me to get up to speed on.  What is the best way to write
cross-backend python web apps?  Is there any abstraction I can use?
With cgi-bin, I use the python "cgi" module, which gives me easy access
to form variables, but I'd like to be able to deploy in the other
backends as well.  What's the best way to do this?  Or is a rewrite
required for each one?

thanks

matt

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


Re: How to create "cross-backend" python web app

2005-07-15 Thread matt
Thanks Paul-

I'll look into WebStack.

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


Re: python and ajax

2005-08-29 Thread matt
Steve-

I recently ported version 1.3 of cpaint to python.  Soon after version
2.0 was released and I haven't really looked at it since.  The 1.3
stuff was really simple though if you understand cgi, then you just
implement a endpoint for your request to call.  The javascript side is
really the only thing new (might be a little learning if you having
done much js).

I think that more advanced ajax libraries like dojo or openrico are
probably better suited to more complicated ajax use.  Though they are
more focused on the js frontend stuff.

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


Re: Bicycle Repair Man usability

2005-08-30 Thread matt
Eclipse's java refactoring tool puts BRM to shame.  This probably has a
lot to do with the static typing of Java and the JDTs nice built in
compiler.  When doing Java development the refactoring support is
really nice (and using a nice ide make's java development almost as
easy as python, since the ide can do the typing for you;) ).

I'd like to hear other's experiences with refactoring in python.  Most
of the projects I work on are quite small relative to some of the Java
projects I've worked on.  Are people using BRM?  Or is refactoring in
python just as easy by hand?  Or is refactoring just a java based
activity

matt

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


Re: testing a website from python

2005-09-20 Thread matt
Here's something I did recently at work.  (Thought it's testing http
digest authentication, the idea would the same (testNoAuth() is
probably doing what you want)).  It contains unittest code and is using
urllib2.
http://blog.spikesource.com/pyhton_testcases.htm

matt

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


urllib2.URLError: when trying to connect through a proxy

2005-03-01 Thread Matt
I'm trying to get the HTML data off of a webpage.  Let's say for the
sake of argument it's the python homepage.  I've googled around and
found some examples that people said worked.  Here's what I've cobbled
together:

#getHTML.py

import urllib
import urllib2
proxy_info = {'user':'us3r',
  'password':'[EMAIL PROTECTED]',
  'host':'MY_PROXY',
  'port':'80'}
os.environ['HTTP_PROXY'] =
'http://%(user)s:%(password)[EMAIL PROTECTED](host)s:%(port)s' % proxy_info
test_url = "http://www.python.org/index.html";
handle = urllib2.urlopen(test_url)
#handle = urllib.urlopen(test_url)
txt = handle.read().lower()
handle.close()
print "Text: "
print txt
#
#end getHTML.py

When I run this with urllib2 I get (with or without a dummy password):
Traceback (most recent call last):
  File "P:\My Documents\Projects\Python\validate_zipcodes.py", line
103, in ?
handle = urllib2.urlopen(test_url)
  File "C:\Python23\lib\urllib2.py", line 129, in urlopen
return _opener.open(url, data)
  File "C:\Python23\lib\urllib2.py", line 326, in open
'_open', req)
  File "C:\Python23\lib\urllib2.py", line 306, in _call_chain
result = func(*args)
  File "C:\Python23\lib\urllib2.py", line 901, in http_open
return self.do_open(httplib.HTTP, req)
  File "C:\Python23\lib\urllib2.py", line 886, in do_open
raise URLError(err)
urllib2.URLError: 

When I run it with urllib.urlopen, I get:
Traceback (most recent call last):
  File "P:\My Documents\Projects\Python\validate_zipcodes.py", line
104, in ?
handle = urllib.urlopen(test_url)
  File "C:\Python23\lib\urllib.py", line 76, in urlopen
return opener.open(url)
  File "C:\Python23\lib\urllib.py", line 181, in open
return getattr(self, name)(url)
  File "C:\Python23\lib\urllib.py", line 287, in open_http
h = httplib.HTTP(host)
  File "C:\Python23\lib\httplib.py", line 1009, in __init__
self._setup(self._connection_class(host, port, strict))
  File "C:\Python23\lib\httplib.py", line 507, in __init__
self._set_hostport(host, port)
  File "C:\Python23\lib\httplib.py", line 518, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '[EMAIL PROTECTED]@MY_PROXY:80'

Obviously, going through Internet Explorer works.

Has anyone else had a similar issue?  I don't know the proxy situation
we have here, so is it possible that the proxy is causing this?

Any help is much appreciated.

Thanks for at least reading this far!
M@

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


Raw Sockets vs. What?

2004-12-11 Thread Matt
Hi,

I'm new to Python (1 week), but I'm writing an out-of-process debugger
for a Python ide. I tried execFile first, but stuff leaked over from
the wx libraries we are using. And, anyway, the next code set is PHP so
this has to be tackled anyway.

So, the question: How to communicate between two instances of the
python interpreter? Specifically, I need to pass the api and objects
from bdb, the base class for the debugger. One interpreter runs the
ide, the other the debugger and client code. We were talking and just
opening a socket and doing the rest from there came up. This, to me,
(admitedly a java guy) seems like a lot of work. If it were just
setting breakppoints and stepping, well ok. But I also want to have
introspection on the debugger side objects.

I could use raw sockets and write a bunch of stuff.

Does anyone have a suggestion about some pythonesque way to tackle
this?

Many thanks in advance,
Matt

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


Re: Raw Sockets vs. What?

2004-12-12 Thread Matt
Thanks for the responses--they were very helpful. I've looked at IDLE
and pyro and I think I'll try using pyro for this first version.

--Matt

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


Re: System bell

2005-03-31 Thread Matt
Try:
import os
os.system('\a')

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


Re: System bell

2005-04-01 Thread Matt
Serves me right for blindlyrunning things from IDLE.

This does work (tested on WinXP only):
import os 
os.system('echo \a')

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


Re: text processing problem

2005-04-07 Thread Matt

Maurice LING wrote:
> Hi,
>
> I'm looking for a way to do this: I need to scan a text (paragraph or

> so) and look for occurrences of " ()". That is, if
the
> text just before the open bracket is the same as the text in the
> brackets, then I have to delete the brackets, with the text in it.
>
> Does anyone knows any way to achieve this?
>
> The closest I've seen is
> (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305306) by
> Raymond Hettinger
>
>  >>> s = 'People of [planet], take us to your leader.'
>  >>> d = dict(planet='Earth')
>  >>> print convert_template(s) % d
> People of Earth, take us to your leader.
>
>  >>> s = 'People of , take us to your leader.'
>  >>> print convert_template(s, '<', '>') % d
> People of Earth, take us to your leader.
>
> """
>
> import re
>
> def convert_template(template, opener='[', closer=']'):
>  opener = re.escape(opener)
>  closer = re.escape(closer)
>  pattern = re.compile(opener + '([_A-Za-z][_A-Za-z0-9]*)' +
closer)
>  return re.sub(pattern, r'%(\1)s', template.replace('%','%%'))
>
> Cheers
> Maurice


Try this:
import re
my_expr = re.compile(r'(\w+) (\(\1\))')
s = "this is (is) a test"
print my_expr.sub(r'\1', s)
#prints 'this is a test'

M@

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


Re: text processing problem

2005-04-07 Thread Matt

Maurice LING wrote:
> Matt wrote:
> >
> >
> > Try this:
> > import re
> > my_expr = re.compile(r'(\w+) (\(\1\))')
> > s = "this is (is) a test"
> > print my_expr.sub(r'\1', s)
> > #prints 'this is a test'
> >
> > M@
> >
>
> Thank you Matt. It works out well. The only think that gives it
problem
> is in events as "there  (there)", where between the word and the same

> bracketted word is more than one whitespaces...
>
> Cheers
> Maurice


Maurice,
I'd HIGHLY suggest purchasing the excellent http://www.oreilly.com/catalog/regex2/index.html";>Mastering
Regular Expressions by Jeff Friedl.  Although it's mostly geared
towards Perl, it will answer all your questions about regular
expressions.  If you're going to work with regexs, this is a must-have.

That being said, here's what the new regular expression should be with
a bit of instruction (in the spirit of teaching someone to fish after
giving them a fish ;-)   )

my_expr = re.compile(r'(\w+)\s*(\(\1\))')

Note the "\s*", in place of the single space " ".  The "\s" means "any
whitespace character (equivalent to [ \t\n\r\f\v]).  The "*" following
it means "0 or more occurances".  So this will now match:

"there  (there)"
"there (there)"
"there(there)"
"there  (there)"
"there\t(there)" (tab)
"there\t\t\t\t\t\t\t\t\t\t\t\t(there)"
etc.

Hope that's helpful.  Pick up the book!

M@

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


Re: text processing problem

2005-04-08 Thread Matt

Maurice LING wrote:
> Matt wrote:
> > I'd HIGHLY suggest purchasing the excellent  > href="http://www.oreilly.com/catalog/regex2/index.html";>Mastering
> > Regular Expressions by Jeff Friedl.  Although it's mostly
geared
> > towards Perl, it will answer all your questions about regular
> > expressions.  If you're going to work with regexs, this is a
must-have.
> >
> > That being said, here's what the new regular expression should be
with
> > a bit of instruction (in the spirit of teaching someone to fish
after
> > giving them a fish ;-)   )
> >
> > my_expr = re.compile(r'(\w+)\s*(\(\1\))')
> >
> > Note the "\s*", in place of the single space " ".  The "\s" means
"any
> > whitespace character (equivalent to [ \t\n\r\f\v]).  The "*"
following
> > it means "0 or more occurances".  So this will now match:
> >
> > "there  (there)"
> > "there (there)"
> > "there(there)"
> > "there  (there)"
> > "there\t(there)" (tab)
> > "there\t\t\t\t\t\t\t\t\t\t\t\t(there)"
> > etc.
> >
> > Hope that's helpful.  Pick up the book!
> >
> > M@
> >
>
> Thanks again. I've read a number of tutorials on regular expressions
but
> it's something that I hardly used in the past, so gone far too rusty.
>
> Before my post, I've tried
> my_expr = re.compile(r'(\w+) \s* (\(\1\))') instead but it doesn't
work,
> so I'm a bit stumped..
>
> Thanks again,
> Maurice

Maurice,
The reason your regex failed is because you have spaces around the
"\s*".  This translates to "one space, followed by zero or more
whitespace elements, followed by one space".  So your regex would only
match the two text elements separated by at least 2 spaces.

This kind of demostrates why regular expressions can drive you nuts.

I still suggests picking up the book; not because Jeff Friedl drove a
dump truck full of money up to my door, but because it specifically has
a use case like yours.  So you get to learn & solve your problem at the
same time!

HTH,
M@

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


Re: Socket Error

2005-04-14 Thread Matt

[EMAIL PROTECTED] wrote:
> Thanks everybody, it works now. I thought I needed to do something
like
> that but it didn't show it in the tutorial so I decided to ask here.

Where was the tutorial?  If it's in the Python docs, perhaps you could
submit a patch to fix it ... ;-)

M@

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


Re: fpectl

2005-04-18 Thread Matt

Sébastien Boisgérault wrote:
> Hi all,
>
> Can anybody tell me why I can't load the fpectl module in my Python
> interpreter:
>
> >>> import fpectl
> Traceback: ...
> ...
> ImportError: No module named fpectl
>
> My platform is Linux (Mandrake 10.x) + Python2.4, built from the
> (python.org) sources and configured with the --with-fpectl option.
>
> Any idea ? Is the Python Library Reference obsolete on this point or
> did I miss something ?
>
> I have understood from the previous posts on the subject that the
whole
> floating-point issue (or specifically IEEE 754 support) is quite
> complex
> and highly platform-dependent. Therefore I guess that I cannot take
for
> granted the expected behavior of fpectl functions. But at least I
> should
> be able to import it, shouldn't I ?
>
> Cheers,
>
> S.B.

I'd assume it's because you're on a non-Unix system.  The docs
(http://www.python.org/doc/2.3.5/lib/module-fpectl.html) say:
Availability: Unix

I'm assuming that means you can't use it on a Windows platform (or any
non-Unix environment)...

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


Re: Which IDE is recommended?

2005-04-27 Thread Matt
The ActiveGrid IDE is a sample app with wxPython. It has a lot of good
features including a source code debugger that allows you to debug wx
apps and set breakpoints from the code editor. I am also biased
though--I work on that IDE and use it for all my coding. Its pretty far
along on Windows and getting better on Linux. We just got it working on
a Mac yesterday so that version won't be out for a bit.

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


Re: Which IDE is recommended?

2005-04-28 Thread Matt
Sorry about that Frank. You have to create a project (New --> Project)
and add your file to it then Run-->Run. This is a bug that slipped past
because we do all of our development using projects and hadn't even
tried the obvious: open file and run. That fix has made its way to the
wx folks, but hasn't been released yet.

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


Re: Which IDE is recommended?

2005-04-28 Thread Matt
Franz,

To ask for help otherwise, use the forums link from
http://sourceforge.net/projects/activegrid/

--Matt

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


web scraping help / better way to do it ?

2016-01-19 Thread Matt
Beginner python user (3.5) and trying to scrape this page and get the ladder
-   www.afl.com.au/ladder .  Its dynamic content so I used lynx -dump to get
a  txt file and parsing that.

Here is the code 

# import lynx -dump txt file
f = open('c:/temp/afl2.txt','r').read()

# Put import txt file into list 
afl_list = f.split(' ')

#here are the things we want to search for
search_list = ['FRE', 'WCE', 'HAW', 'SYD', 'RICH', 'WB', 'ADEL', 'NMFC',
'PORT', 'GEEL', 'GWS', 'COLL', 'MELB', 'STK', 'ESS', 'GCFC', 'BL', 'CARL']

def build_ladder():
for l in search_list:
output_num = afl_list.index(l)
list_pos = output_num -1
ladder_pos = afl_list[list_pos]
print(ladder_pos + ' ' + '-' + ' ' + l)

build_ladder()


Which outputs this.

1 - FRE
2 - WCE
3 - HAW
4 - SYD
5 - RICH
6 - WB
7 - ADEL
8 - NMFC
9 - PORT
10 - GEEL
* - GWS
12 - COLL
13 - MELB
14 - STK
15 - ESS
16 - GCFC
17 - BL
18 - CARL

Notice that number 11 is missing because my script picks up "GWS" which is
located earlier in the page.  What is the best way to skip that (and get the
"GWS" lower down in the txt file) or am I better off approaching the code in
a different way?


TIA

Matt




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


RE: web scraping help / better way to do it ?

2016-01-19 Thread Matt


> -Original Message-
> From: Python-list [mailto:python-list-
> bounces+matt=centralkaos@python.org] On Behalf Of Peter Otten
> Sent: Tuesday, 19 January 2016 9:30 PM
> To: python-list@python.org
> Subject: Re: web scraping help / better way to do it ?
> 
> Matt wrote:
> 
> > Beginner python user (3.5) and trying to scrape this page and get the
> > ladder
> > -   www.afl.com.au/ladder .  Its dynamic content so I used lynx -dump to
> > get
> > a  txt file and parsing that.
> >
> > Here is the code
> >
> > # import lynx -dump txt file
> > f = open('c:/temp/afl2.txt','r').read()
> >
> > # Put import txt file into list
> > afl_list = f.split(' ')
> >
> > #here are the things we want to search for search_list = ['FRE',
> > 'WCE', 'HAW', 'SYD', 'RICH', 'WB', 'ADEL', 'NMFC', 'PORT', 'GEEL',
> > 'GWS', 'COLL', 'MELB', 'STK', 'ESS', 'GCFC', 'BL', 'CARL']
> >
> > def build_ladder():
> > for l in search_list:
> > output_num = afl_list.index(l)
> > list_pos = output_num -1
> > ladder_pos = afl_list[list_pos]
> > print(ladder_pos + ' ' + '-' + ' ' + l)
> >
> > build_ladder()
> >
> >
> > Which outputs this.
> >
> > 1 - FRE
> > 2 - WCE
> > 3 - HAW
> > 4 - SYD
> > 5 - RICH
> > 6 - WB
> > 7 - ADEL
> > 8 - NMFC
> > 9 - PORT
> > 10 - GEEL
> > * - GWS
> > 12 - COLL
> > 13 - MELB
> > 14 - STK
> > 15 - ESS
> > 16 - GCFC
> > 17 - BL
> > 18 - CARL
> >
> > Notice that number 11 is missing because my script picks up "GWS"
> > which is located earlier in the page.  What is the best way to skip
> > that (and get the "GWS" lower down in the txt file) or am I better off
> > approaching the code in a different way?
> 
> If you look at the html source you'll see that the desired "GWS" is inside
a
> table, together with the other abbreviations. To extract (parts of) that
table
> you should use a tool that understands the structure of html.
> 
> The most popular library to parse html with Python is BeautifulSoup, but
my
> example uses lxml:
> 
> $ cat ladder.py
> import urllib.request
> import io
> import lxml.html
> 
> def first(row, xpath):
> return row.xpath(xpath)[0].strip()
> 
> html = urllib.request.urlopen("http://www.afl.com.au/ladder";).read()
> tree = lxml.html.parse(io.BytesIO(html))
> 
> for row in tree.xpath("//tr")[1:]:
> print(
> first(row, ".//td[1]/span/text()"),
> first(row, ".//abbr/text()"))
> 
> $ python3 ladder.py
> 1 FRE
> 2 WCE
> 3 HAW
> 4 SYD
> 5 RICH
> 6 WB
> 7 ADEL
> 8 NMFC
> 9 PORT
> 10 GEEL
> 11 GWS
> 12 COLL
> 13 MELB
> 14 STK
> 15 ESS
> 16 GCFC
> 17 BL
> 18 CARL
> 
> 
> Someone with better knowledge of XPath could probably avoid some of the
> postprocessing I do in Python.
> 
> --
 Thanks Peter, you opened my eyes to a half dozen things here, just what I
needed. 

Much appreciated

Cheers
- Matt


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


snmpset

2016-02-05 Thread Matt
How do I do the equivalent of this in Python?

snmpset -v 2c -c $community $ip .1.3.1.1.4.1.1.1.1.1.1.1.0 s test

and

snmpset -v 2c -c $community $ip .1.3.1.1.4.1.1.1.1.1.1.1.0 i 123

and

snmpbulkget -v2c -c $community -m ALL $ip .1.3.1.1.4.1.1.1.1.1.1.1.1

and

snmpget -v2c -c $community -m ALL $ip .1.3.1.1.4.1.1.1.1.1.1.1.2
-- 
https://mail.python.org/mailman/listinfo/python-list


Creating a function for a directory

2013-11-11 Thread Matt
So I want to take the file, "desktop/test.txt" and write it to 
"desktop/newfolder/test.txt". I tried the below script, and it gave me: 
"IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'". Any 
suggestions would be great.



def firstdev(file):
in_file = open("desktop/%s.txt") % file
indata = in_file.read()
out_file = open("desktop/newfolder/%s.txt", 'w') % file
out_file.write(indata)
out_file.close()
in_file.close()

firstdev("test")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a function for a directory

2013-11-11 Thread Matt
Thank you guys so much. Brain fart moment. I appreciate it
-- 
https://mail.python.org/mailman/listinfo/python-list


Automate deployment of Python application from multiple VCS repositories

2015-04-08 Thread Matt
This seems highly do-able with Ansible. They have a git module, if that's your 
VCS, that fits in here perfectly. 

I would make two lists of variables, the first for repo URL/branch info and the 
second for their destinations. Then Ansible uses simple YAML to write the 
commands. Here's an overly simplified version that I'm typing up quick on my 
phone:

- for each item in /git_variables.yml
  git clone {{ host }} {{ branch }} {{ destination }}

Relevant info is here:
http://docs.ansible.com/playbooks_variables.html
http://docs.ansible.com/playbooks_loops.html
http://docs.ansible.com/git_module.html

I'm in #python and #ansible as heatmeiser if you need any low level detail. 
-- 
https://mail.python.org/mailman/listinfo/python-list


IOError 35 when trying to read the result of call to urllib2.urlopen

2011-09-09 Thread matt
I'm using urllib2's urlopen function to post to a service which should
return a rather lengthy JSON object as the body of its response.
Here's the code:

{{{
ctype, body = encode_multipart(fields, files)
url = 'http://someservice:8080/path/to/resource'
headers = {'Content-Type': ctype, 'Content-Length': str(len(body))}
req = urllib2.Request(url, body, headers)
resp = urllib2.urlopen(req)

resp_body = resp.read()
}}}

When I try to look at "resp_body" I get this error:

IOError: [Errno 35] Resource temporarily unavailable

I posted to the same URI using curl and it worked fine, so I don't
think it has to do with the server.

Any thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOError 35 when trying to read the result of call to urllib2.urlopen

2011-09-10 Thread matt
On Sep 9, 6:02 pm, Steven D'Aprano  wrote:
> matt wrote:
> > When I try to look at "resp_body" I get this error:
>
> > IOError: [Errno 35] Resource temporarily unavailable
>
> > I posted to the same URI using curl and it worked fine, so I don't
> > think it has to do with the server.
>
> Are your Python code and curl both using the same proxy? It may be that one
> is going direct and the other is using a proxy.
>
> Or perhaps the destination is just flaky, and the resource genuinely is
> temporarily unavailable. Or it doesn't like your useragent string and is
> lying.
>
> --
> Steven

No proxy.  It's all local over the loopback interface (probably should
have mentioned that).  The service I'm POSTing to is a Python web app
with CherryPy as the framework.  Also, because of some dependency
issues I'm using Python 2.6.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Mixins

2011-09-22 Thread Matt
I'm curious about what people's opinions are about using mixins in
Python. I really like, for example, the way that class based views
were implemented in Django 1.3 using mixins. It makes everything
extremely customizable and reusable. I think this is a very good
practice to follow, however, in Python mixins are achieved by using
(or perhaps misusing) inheritance and often multiple inheritance.

Inheritance is a very powerful tool, and multiple inheritance is an
even more powerful tool. These tools have their uses, but I feel like
"mixing in" functionality is not one of them. There are much different
reasons and uses for inheriting functionality from a parent and mixing
in functionality from elsewhere.

As a person, you learn certain things from your parents, you learn
other things from your peers all of those things put together becomes
you. Your peers are not your parents, that would not be possible. You
have completely different DNA and come from a completely different
place.

In terms of code, lets say we have the following classes:

class Animal
class Yamlafiable
class Cat(Animal, Yamlafiable)
class Dog(Animal, Yamlafiable)

I've got an Animal that does animal things, a Cat that does cat things
and a Dog that does dog things. I've also got a Yamlafiable class that
does something clever to generically convert an object into Yaml in
some way. Looking at these classes I can see that a Cat is an Animal,
a Dog is an Animal, a Dog is not a Cat, a Cat is not a Dog, a Dog is a
Yamlafiable? and a Cat is a Yamlafiable? Is that really true? If my
objects are categorized correctly, in the correct inheritance
hierarchy shouldn't that make more sense? Cats and Dogs aren't
Yamlafiable, that doesn't define what they are, rather it defines
something that they can do because of things that they picked up from
their friend the Yamlafile.

This is just a ridiculous example, but I think it is valid to say that
these things shouldn't be limited to inherit functionality only from
their parents, that they can pick other things up along the way as
well. Which is easy to do, right?

Dog.something_new = something_new

(I wish my stupid dog would learn that easily)

Ideally, what I would like to see is something like Ruby's mixins. It
seems to me like Ruby developed this out of necessity due to the fact
that it does not support multiple inheritance, however I think the
implementation is much more pure than inheriting from things that
aren't your parents. (although having only a single parent doesn't
make much sense either, I believe there are very few actual documented
cases of that happening). Here is a Ruby snippet:

module ReusableStuff
def one_thing
"something cool"
end
end
class MyClass < MyParent
include ReusableStuff
end

x = MyClass.new
x.one_thing == "something cool"
MyClass.superclass == Object

So I'm inheriting from MyParent and mixing in additional functionality
from ReusableStuff without affecting who my Parents are. This, to me,
makes much more sense than using inheritance to just grab a piece of
functionality that I want to reuse. I wrote a class decorator for
Python that does something similar (https://gist.github.com/1233738)
here is a snippet from that:

class MyMixin(object):
def one_thing(self):
return "something cool"

@mixin(MyMixin)
class MyClass(object):
pass

x = MyClass()
x.one_thing() == 'something cool'
x.__class__.__bases__ ==  (object,)

To me, this is much more concise. By looking at this I can tell what
MyClass IS, who it's parents are and what else it can do. I'm very
interested to know if there are others who feel as dirty as I do when
using inheritance for mixins or if there are other things that Python
developers are doing to mix in functionality without using inheritance
or if the general populous of the Python community disagrees with me
and thinks that this is a perfectly valid use of inheritance.

I look forward to hearing back.

Thanks,
Matthew J Morrison
www.mattjmorrison.com


P.S. - This is a good article about not using inheritance as a code
reuse tool: 
http://littletutorials.com/2008/06/23/inheritance-not-for-code-reuse/
-- 
http://mail.python.org/mailman/listinfo/python-list


simple file flow question with csv.reader

2011-11-02 Thread Matt
Hi All, 

I am trying to do a really simple file operation, yet, it befuddles me...

I have a few hundred .csv files, and to each file, I want to manipulate the 
data, then save back to the original file. The code below will open up the 
files, and do the proper manipulations-- but I can't seem to save the files 
after the manipulation.. 

How can I save the files-- or do I need to try something else maybe with split, 
join, etc..
 

import os
import csv
for filename in os.listdir("/home/matthew/Desktop/pero.ngs/blast"):
with open(filename, 'rw') as f:
reader = csv.reader(f)
for row in reader:
print ">",row[0],row[4],"\n",row[1], "\n", ">", row[2], 
"\n", row[3]



Thanks in advance, Matt
-- 
http://mail.python.org/mailman/listinfo/python-list


match, concatenate based on filename

2011-11-03 Thread Matt
Hi All, 

I am trying to concatenate several hundred files based on their filename..  
Filenames are like this:

Q1.HOMOblast.fasta  
Q1.mus.blast.fasta  
Q1.query.fasta  
Q2.HOMOblast.fasta  
Q2.mus.blast.fasta  
Q2.query.fasta
...
Q1223.HOMOblast.fasta  
Q1223.mus.blast.fasta  
Q1223.query.fasta

All the Q1's should be concatenated together in a single file = 
Q1.concat.fasta.. Q2's go together, Q3's and so on...

I envision something like

for file in os.listdir("/home/matthew/Desktop/pero.ngs/fasta/final/"):
if file.startswith("Q%i"):
   concatenate...

But I can't figure out how to iterate this process over Q-numbers 1-1223

Any help appreciate.




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


Re: Typing letters slowly using sys

2013-04-05 Thread Matt
On Friday, April 5, 2013 10:04:49 AM UTC-4, Matt wrote:
> I am using sys to give the effect that I am typing letters slowly. Basically 
> what I want to have happen is have it show "Loading.." with the word 
> loading appearing instantly and then the periods appearing slowly, as most 
> loading screens do. 
> 
> This is what I have.
> 
> 
> 
> dots = ('')
> 
> for x in dots:
> 
>  sys.stdout.write(x)
> 
>  sys.stdout.flush()
> 
>  time.sleep(0.2)
> 
>   
> 
> I cannot for the life of me figure out how to get the dots to appear on the 
> same line as "Loading". Every way that I have attempted, the word "Loading" 
> appears and then the dots appear on the next line.

Sorry guys, I may have not been clear. The part I pasted does work, but I 
cannot figure out how to get that to print after the word "Loading". So it will 
instantly print "Loading", and then the "..." will appear slowly
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehention

2006-01-19 Thread Matt

Tim Chase wrote:

>
> I'm a tad confused by the help, as it sounds like sets are
> supposed to be first-class citizens, but in ver2.3.5 that I'm
> running here (or rather "there", on a friend's box), I have to
> "import sets" which I didn't see mentioned in the reference manual.
>
> -one of many tims on the list
> tim = Set(["bald", "vegetarian", "loving husband"])
>
> :)

The builtin "set" was added in 2.4, I believe (note lowercase "s"):

http://docs.python.org/whatsnew/node2.html

print "vegetarian".replace("etari","")
:-)

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


Insert characters into string based on re ?

2006-10-12 Thread Matt
I am attempting to reformat a string, inserting newlines before certain
phrases. For example, in formatting SQL, I want to start a new line at
each JOIN condition. Noting that strings are immutable, I thought it
best to spllit the string at the key points, then join with '\n'.

Regexps can seem the best way to identify the points in the string
('LEFT.*JOIN' to cover 'LEFT OUTER JOIN' and 'LEFT JOIN'), since I need
to identify multiple locationg in the string. However, the re.split
method returns the list without the split phrases, and re.findall does
not seem useful for this operation.

Suggestions?

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


Re: How to let a loop run for a while before checking for breakcondition?

2006-08-29 Thread matt
IMHO you're better off avoiding all this...  It makes the code
unnecessarily complicated when you're not sure if this is a performance
bottleneck or not...

Common advice is to write the code as simple as possible first, then go
back and optimize as needed using the profiler.  This is where
extending in C becomes useful, but don't go to that level if it isn't
really needed.

KISS -- Keep It Simple Stupid

thx

m

Hendrik van Rooyen wrote:
> "Claudio Grondi" <[EMAIL PROTECTED]> wrote:
>
>
> | Diez B. Roggisch wrote:
> | > Claudio Grondi schrieb:
> | >
> | >>
> | >> Sometimes it is known in advance, that the time spent in a loop will
> | >> be in order of minutes or even hours, so it makes sense to optimize
> | >> each element in the loop to make it run faster.
> | >> One of instructions which can sure be optimized away is the check for
> | >> the break condition, at least within the time where it is known that
> | >> the loop will not reach it.
> | >>
> | >> Any idea how to write such a loop?
> | >>
> | >> e.g.
> | >>
> | >> counter = 2*64
> | >>
> | >> while counter(BUT DON'T CHECK IT THE FIRST ONE HOUR LONG):
> | >
> | >
> | > now = time.time()
> | > while time.time() - now < 3600.0 or some_other_condition:
> | >...
> | >
> | >
> | > The short circuiting of the or will prevent the execution of
> | > some_other_condition.
> | >
> | >>   ... do something ... # and decrease the counter
> | >>
> | >> Thanks for any hint, but in particular if related to timers on the
> | >> Windows 2000/XP system I am mainly working with.
> | >>
> | >> What do you think about this idea? Does it make sense?
> | >
> | > What idea?
> | This one you haven't probably got from what I have written.
> | I thought, that the introductory text gives enough context to be able to
> | see what I mean, but I was apparently wrong.
> |
> | The idea is to speed up a loop by using a timer interrupt interfering
> | with the loop, so that only after the timer interrupt would occur, the
> | loop will start to check its break condition in each iteration.
> | No checking of any kind in the loop should happen up to that time to
> | minimize the number of operations in each iteration within the loop
> | itself (i.e. the loop more or less won't know, that there is a timer on
> | its way to change the loops behavior at a later time).
> |
> | I hope this above helps to understand what I would like to achieve.
> |
> | Claudio Grondi
>
> I don't think this is usefully possible in python - the problem is that you 
> will
> simply replace one check - The expiry of the counter - with another - to see 
> if
> the interrupt has occurred already -
>
> That said - the way I would do it would be to do something like this (in
> horrible pseudo code):
>
> loop_start:
> do_something()
> jump loop_start
> if counter > end_value:
> break
> jump loop_start
> loop_end:
>
>
> Interrupt_routine:
> replace the first jump to loop_start with a bunch of no - ops
> return
>
> I don't think you can do this in python - it involves altering the running
> loop - but hey maybe I can learn something here...
>
> This example sort of exposes the break for what it is - a jump statement in
> disguise - "look you cant recognise me - I am wearing dark glasses" - and
> "continue" is exactly like that too - the only difference is that the one 
> jumps
> to the end, and the other to the beginning of the loop...
> 
> - Hendrik

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


Mac OS X - Deployment

2006-02-14 Thread Matt
Hi Everybody,

I just spent about an hour googling and still can't find out how to deploy a 
Python app to Mac OS X.

I just finished a simple Hello-World GUI app using wxPython and deployed it to 
a WinXP system using PyInstaller. So I am familiar with the basic tools.

It would be great if I could build an OS X executable from my XP system. Is 
that possible? If so, is it documented anywhere? 

If I can't do it on XP, I suppose I would have to install Python and wxPython 
on a Mac, then copy over my HelloWorld.py file, but what then? I know how to 
make DMG files, but what woudl go into the DMG?

I am used to REALbasic where you write your code and then push the "Build" 
button and executables for Linux, Windows, and Mac are created in less than a 
minute. Maybe the Python world will be as advanced one day...

Thanks,
Matt



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


Re: Mac OS X - Deployment

2006-02-15 Thread Matt
James Stroud <[EMAIL PROTECTED]> wrote:

>py2app works for this. I'm not sure if it works from windows.

That's what I need,

Thanks,
Matt



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


Re: Win32_Process.Create -- not starting process

2006-02-15 Thread Matt
"abcd" <[EMAIL PROTECTED]> wrote:

>.however the python script that is called from the batch script

One thing I have learned about launching programs from batch files like this 
is that if the launched program tries to prompt the user for imput at the 
command line, everthing goes haywire since it has no shell to communicate 
with. It may crash, go into a loop, etc.

Good luck,
Matt



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


Mac OS X Installation Problem

2006-02-16 Thread Matt
Hi Everybody,

1) Does OS X have a thing like the Add/Remove Programs control panel on 
Windows XP?

My Tiger system had Python v2.3.5 on it and I threw the files in the trash and 
installed v2.4.1, which is working fine as far as I can tell. However, when I 
type python at the command line, I get "command not found" so,

2) How do I get OS X to recognize python at the command line?

Thanks,
Matt



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


Komodo - Will it Lock Me In?

2006-02-17 Thread Matt
Hi Everybody,

If I were to use Komodo to write in Python, would it add a lot of goo to my 
code such that I would not be able to switch to another IDE without having to 
claw my way out of a tarpit first?

Any other thoughts on Komodo? I am considering it because I am hoping to find 
a solution to the install-packages-until-you-go-blind aspect of Python. 
Setting up a serious, cross-platform, gui development environment is quite a 
struggle for a newbie.

Thanks,
Matt



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


Re: Komodo - Will it Lock Me In?

2006-02-19 Thread Matt
"Ravi Teja" <[EMAIL PROTECTED]> wrote:

>Matt, in most cases, installing packages in Python is about as easy as
>it gets. 

Yes, it is easy, sort-of. I have installed many, many packages so far. My 
point is that with a polished IDE, you don't have to go through all of this. 
You download an installer, run it, start up the IDE and start writing code. 
There are many such RAD tools. I would like such a thing for Python. I've 
spent several days installing package after package, everything from Eclipse 
to py2app, and I still don't have a good development environment. It seems 
that one must be a Python expert before he can write his first simple 
hello-world app.

My goal was to test out Python by writing a simple GUI app and then deploying 
it to Mac OS X and Windows XP. Using a product such as RealBasic, a totally 
green newbie could accomplish this in a few minutes.. So, I guess my main 
question is, is there such a RAD tool for Python?

Thanks,
Matt



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


Re: Komodo - Will it Lock Me In?

2006-02-19 Thread Matt
Trent Mick <[EMAIL PROTECTED]> wrote:

>Perhaps you are thinking of some of the C/C++ IDEs (like Visual Studio
>on Windows and Xcode on the Mac)

Hi Trent, Ravi,

Actually, I had two things in mind:

1) HTML editors - I made a website using Yahoo Sitebuilder. It's a pretty good 
tool, but I didn't want to use it any more, but could not simply open my HTML 
files with another editor. I had to spend many hours ripping out the 
Sitebuilder goo first.

2) "RAD" tools. If you write code in VisualBasic, you can't use hardly any of 
it in another Basic RAD tool such as RealBasic. They are ostensibly the same 
language, Basic, but in reality there is only a surface resemblance.

I want to avoid this if I can with Python. I want to have my code, and then 
work on it with different tools. I don't want to have to commit to one tool, 
and then pray that the tool remains in existance. I was really pissed off when 
Microsoft killed Visual Basic 6, and I was stuck with a huge mound of now 
worthless code. I have to rewrite *all* of it. I never want to go through that 
again, which is why I am considering Python.

Thanks,
Matt



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


Re: Komodo - Will it Lock Me In?

2006-02-19 Thread Matt
"Peter Decker" <[EMAIL PROTECTED]> wrote:

>You should take a look at Dabo, 

Yes, I have Dabo installed on my system. I made a small test app, but was 
unable to deploy it. I was getting an error from py2exe, I think, about how my 
wxPython installation was not correct. This is the kind of thing I am talking 
about. If Dabo were an integrated system, I wouldn't have to spend many days 
struggling to install package after package and then get them all to play nice 
with each other.

Having said that, I will continue to struggle and like Dabo as the best option 
so far.

Thanks,
Matt



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


Re: Mac OS X Installation Problem

2006-02-19 Thread Matt
[EMAIL PROTECTED] (Alex Martelli) wrote:

>Edit a ~/.bashrc file to add /usr/local/bin to your PATH.

Hi Alex,

Easier said than done for a non-unix expert. Correct me if I am wrong. Bash 
looks at the contents of the PATH variable to decided which directories it 
should scan when parsing a command. If I type "Python -v", it will look in all 
of those directories for a file called "Python" and then execute it, passing 
it the -v parameter. Right?

I've been googling around for about an hour now, and I can't find any 
instructions on how to create or edit a .bashrc file. I tried to make one of 
my own using bash and nano, but got stuck with the save command. It looks like 
I am supposed to use the "M-O" command to save it in Mac format, but I have no 
idea how to type that. A search of the nano docs for "M-O" didn't turn up 
anything either. I also tried to make a .bashrc file on my Windows box and 
copy it to my Mac, but the Finder gave me an error message saying that I'm not 
allowed to make files that begin with a dot.

Is there a web page somewhere that explains this?

Thanks,
Matt



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


Re: Mac OS X Installation Problem

2006-02-19 Thread Matt
Kevin Walzer <[EMAIL PROTECTED]> wrote:

>It's not considered a good idea to trash Apple system files. It's likely
>that system tools that depend on Python (CoreImage scripting comes to
>mind) are now broken and the only way to fix this is to reinstall the OS.

Thanks for the heads up. I thought that Apple had included Python as a 
convenience for its customers. I didn't realize it was actually being used by 
OS X. My Mac seems to be behaving OK, so maybe I don't use any of the Python 
parts, but I will keep that in mind in case it goes haywire in the future.

But this begs the question, how do we upgrade our Python installations if OS X 
needs a certain version? Do we leave the pre-installed version alone and run a 
second Python installation? I suppose that the various package installers 
would know how to do that, right?

Thanks,
Matt



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


Re: Need a little parse help

2005-05-10 Thread Matt
Alex Nordhus wrote:
> Im trying to grab a colum of data from a text file and write it to a
new
> file.
> I am having trouble getting It to write the data to newlines. Python
is
> making it one
> Long string without any spaces when it writes the file. The first
> character is capitalized in colum 2.
> I am trying to grab the 2nd colum in the file.
>
> import sys, string
>
> inputfilenames, outputfilename = sys.argv[1:-1], sys.argv[-1]
>
> for inputfilename in inputfilenames:
>
> inputfile = open(inputfilename,'r')
> outputfile = open(outputfilename, "w")
> for ln in inputfile.readlines():
> words = string.split(ln)
> if len(words) >= 2:
> # print (words[1])
>   outputfile.write(words[1])
>
> When I use just print it prints out fine. Each on a dffrent line just
> the way I want it. But writing the file its all on one line. How do I
> get the data to goto new lines in the new file?
>
>
> Alex Nordhus
> Copy and Paste !
> http://www.pasteaway.com

Everyone else solved the "+'\n'" issue; but just as a nit, you should
use the ".split()" method on the string object ("ln").  In other words,
replace:

words = string.split(ln)
with
words = ln.split()

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


Re: How to find the classname of an object? (was Python Documentation)

2005-05-13 Thread Matt

Christopher J. Bottaro wrote:
> Christopher J. Bottaro wrote:
>
> > Bengt Richter wrote:
> >
> >>  >>> type(obj)
> >>  
> >>  >>> type(obj).mro()
> >>  [, , ,
> >>  [, ]
> >>  >>> tuple(x.__name__ for x in type(obj).mro())
> >>  ('A', 'B1', 'B2', 'C', 'object')
> >
> > Wow awesome, thats exactly what I was looking for.
>
> Wait a sec...why doesn't the following code work then?
>
> class FWException(Exception): pass
> class FWA(FWException): pass
> class FWB(FWA): pass
> class FWC(FWB): pass
> e = FWC()
> print [ cl.__name__ for cl in type(e).mro() ]
>
> Thanks again.
> --C


Is it because you need to inherit from "object"?

class FWException(Exception, object): pass # note "object"
class FWA(FWException): pass
class FWB(FWA): pass
class FWC(FWB): pass
e = FWC()
print [ cl.__name__ for cl in type(e).mro()]

#prints ['FWC', 'FWB', 'FWA', 'FWException', 'Exception', 'object']

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


Re: How to find the classname of an object? (was Python Documentation)

2005-05-13 Thread Matt

Bengt Richter wrote:
> On 13 May 2005 09:37:07 -0700, "Matt"
<[EMAIL PROTECTED]> wrote:
>
> >
> >Christopher J. Bottaro wrote:
> >> Christopher J. Bottaro wrote:
> >>
> >> > Bengt Richter wrote:
> >> >
> >> >>  >>> type(obj)
> >> >>  
> >> >>  >>> type(obj).mro()
> >> >>  [, ,  >'__main__.B2'>,
> >> >>  [, ]
> >> >>  >>> tuple(x.__name__ for x in type(obj).mro())
> >> >>  ('A', 'B1', 'B2', 'C', 'object')
> >> >
> >> > Wow awesome, thats exactly what I was looking for.
> >>
> >> Wait a sec...why doesn't the following code work then?
> >>
> Well, I suspect it actually does work, technically, but I suspect
> it hints at the way old-style classes were implemented in the
environment
> of the new, rather than giving you what you might expect.
>
> >> class FWException(Exception): pass
> >> class FWA(FWException): pass
> >> class FWB(FWA): pass
> >> class FWC(FWB): pass
> >> e = FWC()
> >> print [ cl.__name__ for cl in type(e).mro() ]
> >>
> >> Thanks again.
> >> --C
> >
> >
> >Is it because you need to inherit from "object"?
> >
> >class FWException(Exception, object): pass # note "object"
> >class FWA(FWException): pass
> >class FWB(FWA): pass
> >class FWC(FWB): pass
> >e = FWC()
> >print [ cl.__name__ for cl in type(e).mro()]
> >
> >#prints ['FWC', 'FWB', 'FWA', 'FWException', 'Exception', 'object']
> >
> I'm afraid inheriting explicitly from object will make the exception
unraisable.
> Exceptions are still based on "classic" classes for some reason that
> I don't know enough about to explain.
>
> So if you were hoping to use .mro() with old-style classes to see the
> old-style inheritance chain, as opposed to new-style inheritance that
> underlies access to special entities involved in the implementation
of the old, sorry ;-/
>
> At least that's the way it looks to me, without digging in that part
of the code.
>
> Regards,
> Bengt Richter

D'oh!  So I tested the .mro() functionality but not the
Exception-raisableness (?).

It seems unintuitive to me as to why inheriting from  "object" would
prevent something that also inherited from "Exception" from being
raised.  Does anyone have insight into why this happens?

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


Re: How to find the classname of an object? (was Python Documentation)

2005-05-13 Thread Matt

Bengt Richter wrote:
> On 13 May 2005 14:59:13 -0700, "Matt"
<[EMAIL PROTECTED]> wrote:
> >
> >Bengt Richter wrote:
> [...]
> >> I'm afraid inheriting explicitly from object will make the
exception
> >unraisable.
> >> Exceptions are still based on "classic" classes for some reason
that
> >> I don't know enough about to explain.
> >>
> >> So if you were hoping to use .mro() with old-style classes to see
the
> >> old-style inheritance chain, as opposed to new-style inheritance
that
> >> underlies access to special entities involved in the
implementation
> >of the old, sorry ;-/
> >>
> >> At least that's the way it looks to me, without digging in that
part
> >of the code.
> >>
> >> Regards,
> >> Bengt Richter
> >
> >D'oh!  So I tested the .mro() functionality but not the
> >Exception-raisableness (?).
> >
> >It seems unintuitive to me as to why inheriting from  "object" would
> >prevent something that also inherited from "Exception" from being
> >raised.  Does anyone have insight into why this happens?
> >
> I googled for some discussion and found something straight from the
BDFL:
>
>
http://mail.python.org/pipermail/python-dev/2005-January/051098.html
>
> with a lot of interesting followup. Don't know what the status of the
> patch is now.
>
> Regards,
> Bengt Richter

Great googling!  Reading through to the end it seems that there will be
a patch for 2.5:
http://sourceforge.net/tracker/index.php?func=detail&aid=1104669&group_id=5470&atid=305470
(although from the thread you found, it appears to be somewhat
temporary in case everything starts breaking :-)   )

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


Re: no win32com.client

2005-05-23 Thread Matt

plsullivan wrote:
> In 2.4.1 the following is generated from a script that ran in 2.2:
>
> import sys, string, os, win32com.client
> ImportError: No module named win32com.client
>
> thanks for any input,
> Phil

Have you downloaded the win32com extensions?

http://starship.python.net/crew/mhammond/win32/Downloads.html

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


Re: Symbol Tables

2005-05-26 Thread Matt


Dave Zhu wrote:
> Hello,
>
> I would like to know more about Python's symbol
> tables. How are symbol tables implemented in Python?
> Hash tables, lists, or arrays? I would really
> appreciate if there is any documentation that you can
> provide. Thank you in advance.
>
> Dave
>
>
>
> __
> Discover Yahoo!
> Use Yahoo! to plan a weekend, have fun online and more. Check it out!
> http://discover.yahoo.com/

Google is your friend:
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLD,GGLD:2004-49,GGLD:en&q=python+symbol+table

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


Re: Sending mail from 'current user' in Python

2005-06-10 Thread Matt


Mike Meyer wrote:
> Leo Breebaart <[EMAIL PROTECTED]> writes:
>
> > I can get the username info (at least on Unix) via the 'pwd'
> > module, but that still leaves me with the domainname, or rather
> > the mailname, and I have not been able to spot a way of finding
> > that from within Python. (I could try opening /etc/mailname by
> > hand, but how standard is that filename/location?)
>
> Not very. Certainly doesn't exist on FreeBSD, and doesn't appear
> anywhere in the sources for my UMA.
>
> BTW, an alternative for the username is the USER environment
> variable. I don't know whether or not it exists on Windows.
>
> > I've also tried opening a pipe to sendmail, and feeding the
> > message to that instead. This too works great (and does give an
> > appropriate default 'From'), but that also turns my problem into
> > the problem of finding the location of the sendmail program,
> > which doesn't seem like much of an improvement, portability-wise.
>
> Well, you could provide a list of places to look for it. But you're
> right, this doesn't help much with portability.
>
> > Finally, if at all possible I'd also like to get this working on
> > Windows, so I'd rather stick with the standard smtplib if I can.
>
> smtplib needs an SMTP server to connect to. For unix systems, this is
> typically localhost. What do you use for Windows systems? Or are you
> connecting to your machine to deliver the mail?
>
> The problem with getting this working on Windows is that, IIRC, the
> information you need is configured in the UMA, and not in some
> system-wide location, at least on some versions of Windows, and it
> typically is unrelated to the name of the Windows box you're on.
>
> Given those constraints, the simple solution is probably to ask the
> user for the information you need.
>
> Failing that, and assuming os.env['USER'] exists on windows, you could
> try:
>
> 1) Looking up the IP address of the host in question. Not the
>interface - you need the address the outside world sees.
>See http://www.whatismyip.com/ > for example.
> 2) Do a reverse DNS lookup on that ip address to get a host name.
>If they've got a dynamic IP address, this will probably be
>something ugly, if you get anything at all.
> 3) Start doing MX lookups on that host name, stripping off one
>domain level at a time from the left until you get an address
>with an MX record, or you've got nothing left. This assumes
>that an MX record will exist for the part of the domain name
>which get mail - which may not be true.
>
> This entire procedure also assumes that the user reads mail using
> their ISP-provided maildrop, which may not be true.
>

This does work (at least on WinXP Pro, using python 2.3.4):

>>> os.environ["USERNAME"]
'myusername'



>--
> Mike Meyer <[EMAIL PROTECTED]>
> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

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


converting datetime object in UTC to local time

2007-07-03 Thread Matt
Hi all,

So a lot of digging on doing this and still not a fabulous solution:

import time

# this takes the last_modified_date naive datetime, converts it to a
# UTC timetuple, converts that to a timestamp (seconds since the
# epoch), subtracts the timezone offset (in seconds), and then
converts
# that back into a timetuple...   Must be an easier way...
mytime = time.localtime(time.mktime(last_modified_date.utctimetuple())
- time.timezone)

lm_date_str = time.strftime("%m/%d/%Y %I:%M %p %Z", mytime)

last_modified_date is a naive datetime.datetime object


A previous version gave me something like:

mytime =
datetime.datetime.fromtimestamp(time.mktime(last_modified_date.utctimetuple())
- time.timezone)

lm_date_str = mytime.strftime("%m/%d/%Y %I:%M %p %Z")

But this gave me no timezone since the datetime object is still
naive.  And I'm going from a datetime to a timetuple to a timestamp
back to a datetime...

All this seems like a lot of monkeying around to do something that
should be simple -- is there a simple way to do this without requiring
some other module?

thx

Matt

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


Editor with visual SCC / TFS support ?

2007-01-26 Thread Matt
Company has switched to MS Team Foundation Server from VSS. Need a
programmers text editor that interfaces with TFS or SCC providers to
visually provide checkin/out status on project files. So far, in all of
the editors I have used, some support SCC interfaces, but do not show
the file status.

The current alternative is to load Visual Studio (or the TFS client
which is simply a subset of VS), simply to manage checkins. Using
command line calls is also an options, but visualizing the file status
would be more helpful.

Suggestions?

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


Re: Some python syntax that I'm not getting

2007-12-08 Thread Matt

Think of it as using a name instead of a position for your "%s".

In addition to what others already said, I thought I'd add an example
of where this is useful.
One place where you don't just want to have a position is when doing
internatiolization.
When translating for example:
"I'm going by %(transport)s to %(place)s" % ( {'transport' : 'car',
'place' : 'mexico'} )

In another language, the 'place' and 'transport' might not be in the
same order in the sentence, so pretty much the only way to get it
right is to use named parameters instead of positions.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get number of compressed bytes from GzipFile

2008-03-14 Thread Matt
Hi all,

I'm using the gzip module to return a gzip response from a small
python httpserver.  I'd like to know the number of bytes written to
the underlying socket, but it doesn't seem to support the tell()
function.  This works fine for a file:

[15:39:51] mattb ~ $ cat mygzip.py
#!/usr/bin/env python

import os
import gzip

f = open("tmp.gz", "wb")
gz = gzip.GzipFile('', 'wb', 6, f)

for i in xrange(100):
gz.write('abcdefg' * 100)

gz.flush()

print gz.tell()
print f.tell()

gz.close()
f.close()

print os.stat('tmp.gz').st_size
[15:40:17] mattb ~ $ ./mygzip.py
7
141
151

So I wrote 7 raw bytes which gets compressed to 151 bytes -- I
guess the 10-byte difference is a gzip header or something?

Is there any way to get this same functionality when using a socket?

thx

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


using google search api for python

2008-12-12 Thread Matt
You might want to try this Google Search API for
Python<http://blackcodeseo.com/google-search-api-for-python/>.


Sample implementation:

>>> from Google import Google, search
>>> results = search('blackcodeseo.com', 3)
>>> for result in results:
… print 'Title: %s' % (result.title())
… print 'Url: %s' % (result.url())
… print 'Description: %s' % (result.description())
… print
…
Title: Black Code SEO
Url: http://blackcodeseo.com/
Description: Oct 29, 2008 … Black Code SEO. Programatically Automating SEO …
Download BlackCodeSeo Navigator. Run python setup.py install …

Title: Have A Question?
Url: http://blackcodeseo.com/have-a-question/
Description: If you have any questions about anything, you can reach me at
m...@blackcodeseo. com and I will be happy to reply. Your questions may be
posted on the site …

Title: SpiderMonkey « Didier Stevens
Url: http://blog.didierstevens.com/programs/spidermonkey/
Description: The exact post is
http://blackcodeseo.com/python-spidermonkey-navigator/. Comment by Matt —
Wednesday 29 October 2008 @ 20:56. Thanks. …

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


ctypes, function pointers and a lot of trouble

2008-05-28 Thread Matt

Hi friends,

Okay so well, I have quite a problem right now with a file stream. What 
I am doing is to use the Cannon SDK dlls to get control over my old 
Cannon A60 Camera for some surveillance useage.


By using ctypes it all worked well until now. I am able to load the 
dlls, use a lot of functions, am able to connect to the camera, read out 
some params, send commands etc... but now I am stuck with reading the 
picture data.


In C the code looks as follows (found in an supplemental *.h SDK file:

--CODE-

#define cdSTDCALL __stdcall

typedef voidcdSTDCALL cdSOpen(cdContext contextH, cdPermission, 
cdError* err);

typedef voidcdSTDCALL cdSClose(cdContext contextH, cdError* err);
typedef voidcdSTDCALL cdSRead(cdContext contextH, void* buf, 
cdUInt32* bufsize, cdError* err);
typedef voidcdSTDCALL cdSWrite(cdContext contextH, const void *buf, 
cdUInt32* bufsize, cdError *err);
typedef voidcdSTDCALL cdSSeek(cdContext contextH, cdWhence, cdInt32 
offset, cdError* err);

typedef cdInt32 cdSTDCALL cdSTell(cdContext contextH, cdError* err);
typedef voidcdSTDCALL cdSProgress(cdContext contextH, cdUInt16 
percentDone, cdError* err);


/* cdStream
*/
typedef struct {
   cdContext contextH;
   /* stream I/O function pointers */
   cdSOpen*  open;
   cdSClose*  close;
   cdSRead*  read;
   cdSWrite*  write;
   cdSSeek*  seek;
   cdSTell*  tell;
} cdStream;

/* cdStgMedium
*/
typedef struct {
 cdMemType  Type;   /* Type of the medium (u). */
 union {
  cdChar*  lpszFileName;
  cdStream*   pStream;
  #ifdef   macintosh
  cdFSSpec*   pFSSpec;
  #endif
 }u;  /* Union of all transfer medium */
} cdStgMedium;

--\CODE

and this is the function definition that should give me access to the 
data stream (available via DLL):


--CODE-

cdCAPI CDGetReleasedData(
  cdHSource hSource,
  cdProgressCallbackFunction * pCallbackFunc,
  cdContext Context,
  cdProgressOption ProgressOption,
  cdReleaseImageInfo* pInfo,
  cdStgMedium* pStgMedium
);

--\CODE

So, since I'm no C-Professional, I can only guess what that code does. 
With some previous commands I tell the camera to make a picture. This 
picture is then automatically moved to the PCs RAM and with the function 
above (CDGetReleasedData) I should be able to access this stream. Now I 
havn't accessed any stream with ctypes yet so I have only a rough idea 
how it could work.


The following are the relevant parts of my code that don't work:

--CODE-

# Definitions:

class cdReleaseImageInfo(Structure):
_fields_ = [("SequenceID", c_uint),
 ("DataType", c_uint),
 ("Format", c_ubyte),
 ("DataSize", c_uint),
 ("Filename", c_char * 2)]


class cdStream(Structure):
_fields_ = [("contextH", c_uint),
 ("open", c_uint),
 ("close", c_uint),
 ("read", c_uint),
 ("write", c_uint),
 ("seek", c_uint),
 ("tell", c_uint)]

class memunion(Union):
_fields_ = [("lpszFileName", c_char),
 ("pStream", cdStream)]


class cdStgMedium(Structure):
_fields_ = [("Type", c_uint),
 ("u", memunion)]




# command:

datainfo = cdReleaseImageInfo()
data = cdStgMedium()
errorcode = cdsdk.CDGetReleasedData(devicehandle, byref(cbfunct), 
c_uint(1), c_uint(1), byref(datainfo), byref(data))


--\CODE


The function "cdsdk.CDGetReleasedData" itself gets executed correctly, 
but returns an "Invalid Parameter" errorcode. there's also no useful 
data whereas datainfo gets written correctly. I know that my cdStream 
can't work, facing the C-code, but what'd be the right cdStream class? 
What can I do? Any ideas?


Best regards and thanks,
Matt

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


Re: ctypes, function pointers and a lot of trouble

2008-05-29 Thread Matt
Okay, thanks a lot for your reply Nick, I think you pushed me back on 
the right way.


Now I started with trying to implement the callback functions and am 
stuck at the following point:


I define my classes/structures/unions:

--CODE-

class cdStream(Structure):
_fields_ = [("contextH", c_uint),
 ("open", c_void_p),
 ("close", c_void_p),
 ("read", c_void_p),
 ("write", c_void_p),
 ("seek", c_void_p),
 ("tell", c_void_p)]

class memunion(Union):
_fields_ = [("lpszFileName", c_char_p),
 ("pStream", cdStream)]


class cdStgMedium(Structure):
_fields_ = [("Type", c_uint),
 ("u", memunion)]

--\CODE

then i define my functions (right now I do just nothing) and at the same 
time I define the datatypes like they're listed in my C sample program:



--CODE-

def pystreamopen (contextH, mode, pErr):
pass

cstreamopen = CFUNCTYPE(c_uint, c_ushort, c_uint)

def pystreamclose (contextH, pErr):
pass

cstreamclose = CFUNCTYPE(c_uint, c_uint)

def pystreamread (contextH, pBuf, pBufsize, pErr):
pass

cstreamread = CFUNCTYPE(c_uint, c_void_p, c_uint, c_uint)

def pystreamtell (contextH, pErr):
pass

cstreamtell = CFUNCTYPE(c_uint, c_uint)

def pystreamwrite (contextH, origin, offset, pErr):
print "writing..."
pass

cstreamwrite = CFUNCTYPE(c_uint, c_void_p, c_uint, c_uint)

--\CODE

and now the problem starts: i want the pointers in the cdStream 
Structure point at my functions and tried to do it the following way:



--CODE-

data = cdStgMedium()
data.type = 0
data.u.pStream.contextH = c_uint(3) #must be some kind of identifier.
data.u.pStream.open = cstreamopen(pystreamopen)
data.u.pStream.close = cstreamclose(pystreamclose)
data.u.pStream.write = cstreamwrite(pystreamwrite)
data.u.pStream.tell = cstreamtell(pystreamtell)
data.u.pStream.read = cstreamread(pystreamread)

--\CODE

unfortunately that doesn't work because Python returns a TypeError: 
incompatible types, CFunctionType instance instead of c_void_p instance


Any ideas/help (please)?

Best regards,
Matt


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


Re: ctypes, function pointers and a lot of trouble

2008-06-02 Thread Matt

Hi,

okay, thanks now my DLL function seems to accept the functions given, 
but instead of running my program keeps crashing (with windows address 
violation errors). I did some further investigations on that and figured 
out that the contextH variable is not just an identifier as I thought, 
but a quite complicated datastreamhandler.


Now to get it to work I additionally need to implement the following c 
Structures:


--CODE-

/* The internal data structure object of a stream */
typedefstructtagMemStreamData
{
cdCharmode;
cdInt32lPos;
cdUInt32dwVisibleSize;
cdUInt32dwBufferSize;
cdChar*cpBuffer;
}MemStreamData;

typedefstructtagFilStreamData
{
cdCharszFileName[MAX_PATH];
HANDLEhFile;
}FilStreamData;

--\CODE

This function just creates the pStream filestream (which is what I have 
to do too)


--CODE-

BOOLCreateMyFilStream(cdStream*pStream,
cdChar*szFileName )
{
FilStreamData*pFilStrm;

/* The domain for data is secured. */
pFilStrm = new FilStreamData;
if( pFilStrm == NULL )
{
returnFALSE;
}

/* Data is changed the first stage. */
pFilStrm->hFile = INVALID_HANDLE_VALUE;
strcpy( pFilStrm->szFileName, szFileName );

pStream->contextH = (cdContext)pFilStrm;
pStream->close = _CloseMyFilStream;
pStream->open = _OpenMyFilStream;
pStream->read = _ReadMyFilStream;
pStream->seek = _SeekMyFilStream;
pStream->tell = _TellMyFilStream;
pStream->write = _WriteMyFilStream;

returnTRUE;
}


--\CODE



Now my solution is the following:


--CODE-

class MemStreamData(Structure):
_fields_ = [("mode", c_byte),
 ("lPos", c_uint),
 ("dwVisibleSize", c_uint),
 ("dwBufferSize", c_uint),
 ("cpBuffer", POINTER(c_char))]

class FilStreamData (Structure):
_fields_ = [("szFileName", c_char * 30),
 ("hFile", c_uint)]


--\CODE

and the code to fill all that with the right data is the following:

--CODE-

datainfo = cdReleaseImageInfo()

databuf = c_char * 10
cbuffer=MemStreamData()
cbuffer.mode = c_byte(0)
cbuffer.lPos = c_uint(0)
cbuffer.dwVisibleSize = c_uint(10)
cbuffer.dwBufferSize = c_uint(10)

#this line does not work, wrong datatype!?
cbuffer.cpBuffer = POINTER(databuf)

cpointer = cast(cbuffer, POINTER(c_uint))
stream = cdStream()
stream.contextH=cpointer
stream.open = cstreamopen(pystreamopen)
stream.close = cstreamclose(pystreamclose)
stream.write = cstreamwrite(pystreamwrite)
stream.tell = cstreamtell(pystreamtell)
stream.read = cstreamread(pystreamread)



data = cdStgMedium()
data.Type = c_uint(1)
data.u.pStream = POINTER(cdStream)(stream)

--\CODE----

Does anyone see where the errors are?

Best regards and thanks a lot,
Matt






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


Re: Books for programmers

2008-06-03 Thread Matt

Hi,

Hm, depends of course, how good your programming skills are in the 
languages you knwo already, but I rely on the book "Beginning Python - 
From Novice to Professional" by Magnus Lie Hetland, published by Apress.


And for GUI programming I use the official wxPython book. Both books are 
really worth their money and with some programming skills there's no 
need to read every line because it's easy to navigate through the books 
and find the function/structure/whatever you're looking for.


Best regards,
Matt


V wrote:

Hi,

I'm a C++, Java and C programmer, and I'm searching for a (preferably
printed) book that teaches me the "Python idioms", i.e. the "Python
way" of doing something.

Ideally, I'm searching for a book like "Effective C++" or "Effective
Java", that does not lose time teaching what is a class, or a
function, or a loop, but that enters into details and describes not
only the "how", but also the "why".

I read the book "Dive into Python", but I found too schematic and not
enough advanced for my interests.

I generally do not like books from O'Reilly, while I prefere those
from Addison Wesley.

Best regards.

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


Re: ctypes, function pointers and a lot of trouble

2008-06-03 Thread Matt

Hello!

ouch, I should have seen that c_char... :S Well, I guess I just prove 
that it's useless to go to work and do some programming while having a 
headache like I had yesterday...


okay well, back to topic:

The DLL function seems to accept my parameters now, but unfortunately 
Python terminates after the DLL gets the result from the "open" callback 
function (at least its printouts are the last I get before it 
terminates). So without any kind of error message it's getting more 
difficult now.


Well, since I didn't invest much time into my callback functions I 
suspect the error must be somewhere in there.


This is my code:

--CODE-

class MemStreamData(Structure):
_fields_ = [("mode", c_byte),
 ("lPos", c_uint),
 ("dwVisibleSize", c_uint),
 ("dwBufferSize", c_uint),
 ("cpBuffer", POINTER(c_char))]

class FilStreamData (Structure):
_fields_ = [("szFileName", c_char * 30),
 ("hFile", c_uint)]






def pystreamopen (contextH, mode, pErr=0):
print "opening..."
print contextH
print mode
print pErr
return 0

cstreamopen = CFUNCTYPE(c_uint, c_ushort, c_uint)

def pystreamclose (contextH, pErr):
print "closing..."
return 0

cstreamclose = CFUNCTYPE(c_uint, c_uint)

def pystreamread (contextH, pBuf, pBufsize, pErr):
print "reading..."
return 0

cstreamread = CFUNCTYPE(c_uint, c_void_p, c_uint, c_uint)

def pystreamtell (contextH, pErr):
print "telling..."
return 0

cstreamtell = CFUNCTYPE(c_uint, c_uint)


def pystreamseek (contextH, origin, offset, pErr):
print "seeking..."
return 0

cstreamseek = CFUNCTYPE(c_uint, c_uint, c_uint, c_uint)


def pystreamwrite (contextH, origin, offset, pErr):
print "writing..."
return 0

cstreamwrite = CFUNCTYPE(c_uint, c_void_p, c_uint, c_uint)


class cdStream(Structure):
_fields_ = [("contextH", POINTER(MemStreamData)),
 ("open", cstreamopen),
 ("close", cstreamclose),
 ("read", cstreamread),
 ("write", cstreamwrite),
 ("seek", cstreamseek),
 ("tell", cstreamtell)]

-/CODE-



This is the way I create the vars:




--CODE-


databuf = create_string_buffer(10)
cbuffer=MemStreamData()
cbuffer.mode = c_byte(0)
cbuffer.lPos = c_uint(0)
cbuffer.dwVisibleSize = 10
cbuffer.dwBufferSize = 10
cbuffer.cpBuffer = databuf

stream = cdStream()
stream.contextH = POINTER(MemStreamData)(cbuffer)
stream.open = cstreamopen(pystreamopen)
stream.close = cstreamclose(pystreamclose)
stream.write = cstreamwrite(pystreamwrite)
stream.tell = cstreamtell(pystreamtell)
stream.read = cstreamread(pystreamread)


data = cdStgMedium()
data.Type = c_uint(1) # 0...FilStream 1...MemStream
data.u.pStream = POINTER(cdStream)(stream)

errorcode = cdsdk.CDGetReleasedData(devicehandle, byref(cbfunct), 
c_uint(0), c_uint(0), byref(datainfo), POINTER(cdStgMedium)(data))


--/CODE-



Now I have two problems:

1st: since contextH is not a c_uint (and pErr is a pointer) as I thought 
earlier, I tried to change my definition of the open function to:


cstreamopen = CFUNCTYPE(POINTER(MemStreamData), c_ushort, POINTER(c_uint))

unfortunately that throws an error when I try to:

stream.open = cstreamopen(pystreamopen)


2nd: as may saw, I defined "def pystreamopen (contextH, mode, pErr=0)". 
The pErr variable should be a pointer to a c_uint where my function can 
tell the DLL that opening the stream went well (or give some errorcode).


When I do not define pErr=0 and simply say pErr, I get the following error:

Traceback (most recent call last):
 File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 206, in 
'calling callback function'

TypeError: pystreamopen() takes exactly 3 arguments (2 given)

At first I thought okay, maybe there's no pErr and there's some error in 
the C-Code, but when I do "def pystreamopen (contextH, mode)" I get the 
same Error with:

TypeError: pystreamopen() takes exactly 3 arguments (2 given)


Any ideas?


And another question: my callback functions are all defined as void... 
in C. That means that there shouldn't be anything returned. I tried this 
by using the pass statement, but got an error that returntype int was 
expected. Also "return" or "return None" don't work. Why?




Puh, long mail again... hope you're so kind again and take the time to 
help me out.


Best regards from Austria,
Matt

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


Re: ctypes, function pointers and a lot of trouble

2008-06-03 Thread Matt



The docs say CFUNCTYPE(restype, *argtypes), so:

cstreamopen = CFUNCTYPE(c_uint, c_ushort, c_uint)

is saying that the result type is c_uint, not void. I think you need:

cstreamopen = CFUNCTYPE(None, c_uint, c_ushort, c_uint)

instead.


Hm, thanks, now I can access my data in the functions and also write 
them but the program keeps terminating right at the point when the 
"open" function finishes. Unfortunately everything closes and I get no 
error messages.


I did some additional work in the meantime and changed my code so it has 
the correct datatypes now:


--CODE

def pystreamopen (contextH, mode, pErr):
print "opening..."
print contextH.contents.dwBufferSize #just to check the structure
print mode  #tells about what the DLL wants to do with this stream
contextH.contents.mode = c_byte(5) #5=Permission to read and write
contextH.contents.lPos = c_uint(0) #start position

print pErr.contents
pErr.contents = c_uint(0)


cstreamopen = CFUNCTYPE(None, POINTER(MemStreamData), c_ushort, 
POINTER(c_uint))


def pystreamclose (contextH, pErr):
print "closing..."
pass

cstreamclose = CFUNCTYPE(None, POINTER(MemStreamData), POINTER(c_uint))

def pystreamread (contextH, pBuf, pBufsize, pErr):
print "reading..."
pass

cstreamread = CFUNCTYPE(None, POINTER(MemStreamData), c_uint, c_uint, 
POINTER(c_uint))


def pystreamtell (contextH, pErr):
print "telling...

.
.
.etc...

--/CODE

and the function call:

--CODE

errorcode = cdsdk.CDGetReleasedData(devicehandle, byref(cbfunct), 
c_uint(0), c_uint(0), byref(datainfo), POINTER(cdStgMedium)(data))


--/CODE


while it's running my program prints the following and then 
exits/terminates:


>>> opening...990001
>>> 2
>>> c_ulong(0L)
>>> Script terminated.  ##This is a message by my editor (SPE)

I also tried different editors, but get the same result...



Anyway, meanwhile  decided to try a different approach. Maybe I have 
more luck by having the function write the data directly into a file on 
the HDD.

Doe anyone know how to translate the following into Python/ctypes?

I googled quite a lot before but all topic-related I found was my own 
posting here in this NG :S


--CODE

pFilStrm->hFile = CreateFile(	pFilStrm->szFileName,			 
dwDesiredAccess,dwShareMode,	NULL,	 
dwCreationDisposition,FILE_ATTRIBUTE_NORMAL,NULL );



--/CODE

This function is obviously a default C-function that generates a file 
and returns a c-handle to that file. In my case I'd need exactly such a 
handle to get things working...


Furthermore there's a writefile function I'd need to translate too:

--CODE

WriteFile( pFilStrm->hFile, pBuf, dwNumberOfBytesToWrite, pBufsize, NULL );

--/CODE


Ideas?

Thanks and best wishes,
Matt
--
http://mail.python.org/mailman/listinfo/python-list


Advice on tools/technologies/books, etc.

2008-04-12 Thread Matt
I would like to create a web-based tool for risk management. The tool
actually currently exists, but it was programmed in about 1998 using
old VB, etc, and we are updating it & moving it to the web. Basically,
as a first step, i'd like to create a basic web site that takes user
input, gets data from MySQL (i might pickle it, not yet sure) and then
runs some numpy routines & outputs the results. This will give us a
platform to develop the backend. My intermediate goal is to have an
asynchronous site in which as users adjust settings, the computations
are run & graphs updated. (the computations are pretty simple, btw).
My fantasy goal would be to combine that w/ google gears so the users
could use it online or offline, but that's probably just fantasy.

So, here are my constraints: I know Python & HTML (and lots of other
non-germane languages) but I don't know any javascript or ruby or XML.
What is the lowest cost path from here to there? I have been totally
out of the loop for this whole web 2.0 thing (I'm an economics
professor). Will it be possible for me to put together an async site
with only python? (I hesitate to use the term AJAX, b/c its unclear to
me how generic it is--do all async sites use javascript? can someone
clarify this?) If so, does it make sense to go ahead and start trying
to learn Turbogears or Pylons? Will they be able to create async
sites? Is there an easier way to do it? (Easy defined as me not having
to learn a 7th programming language) I have looked at Spyce, and that
seems an easy way to do the basic (step 1) site, but its not at all
clear that I can do async with it. CherryPy looks like it has a
steeper learning curve, but it also appears that the route to async is
clearer.

I know where I want to go, and I know what I can do now. I don't mind
getting deeper into Python, but I'd love not to have to learn a bunch
of other languages if I can avoid it. Any thoughts/comments?

TIA,
Matt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Lib/test/test_mimetools.py

2006-03-10 Thread matt
Hi,

in the file Lib/test/test_mimetools.py on line 30 the call to 
mimetools.choose_boundary() fails if the machine that the tests are 
running on does not have a hostname that maps to an IP address.

I would have thought that the test should be 'skipped' rather than fail?

I don't know if this has been discussed before but any feedback would be 
appreciated. 

Would any body be interested in a patch to make the test skip if 
hostname does not have an designated IP?

Thanks

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


[ANN] jsonrpclib for accessing JSON-RPC from python

2006-03-27 Thread matt
Folks-

I've created some python code for accessing JSON-RPC (think xmlrpc but
replace XML with JSON).  I've written an article about it here:
http://developer.spikesource.com/wiki/index.php/Article:Accessing_JSON-RPC_with_Python

Let me know if you have any questions or feedback.

I also have a question for the python community on coding style.  As I
said above, replace xml with JSON, well that's basically what I did.  I
took the code for xmlrpclib and made it serialize to json instead of
xml.  I didn't subclass xmlrpclib.ServerProxy, but probably could have
and made the library about 15 lines of code rather than 300.

I didn't because I thought it made the code more understandable if it
was all in one place.  Also, if in the code diverges in the future, it
will be less confusing.

Should I have subclassed?  Or should xmlrpclib be refactored to
FOOrpclib, and have xmlrpclib and jsonrpclib derive from them?
(Probably not, since it's in the stdlib...)

thanks

matt

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


embed notepad into a frame widget

2006-03-27 Thread Matt
all,

trying to load an application (notepad for instance) and have it sit 
inside a Python application window. When the main window maximises or 
minimises, the (notepad) app follows.

I am pretty sure I need to use a frame widget under tkinter (win32) but 
not exactly sure how to do it.

I can make the frame but not embed notepad.

do I use something like this?


from Tkinter import *
master = Tk()
frame = Frame(width=768, height=576, bg="", colormap="new")
frame.pack()
video.attach_window(frame.window_id())<--- not sure!!
mainloop()


Thanks

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


Re: embed notepad into a frame widget

2006-03-30 Thread Matt
Diez B. Roggisch wrote:

> You are pretty wrong being sure :) Under windows, it is indeed possible to
> embed certain applications into others - the related technical term is
> conveniently called OLE (Object lining and embedding). 

Thanks,

at least I didnt spend two much time on it :)

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


Re: Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread matt
Suggest keeping it simple:

def use_file():
  return open(options.filename).readlines()

m

News wrote:
> Hi Everyone,
>
>
> The attached code creates client connections to websphere queue managers
> and then processes an inquiry against them.
>
> The program functions when it gets options from the command line.
>
> It also works when pulling the options from a file.
>
> My issue is that it only processes the first line of the file.
>
> Does anyone know why this might be the case?
>
> The use_file() function should be returning each file line.
>
> Any help you can provide on this would be greatly appreciated.
>
> Thanks
>
>
> #!/usr/bin/python
> #
> # Programmer: Andrew Robert
> #
> # Function: Generic method to extract information from a queue manager
> #   This script is intended to be run from the command line to
> return values
> #   based on supplied keys
> #
> #   Depending on whether the -d command switch is used or not,
> the output of this script
> #   will go to the screen or be e-mailed
> #
> #   The e-mailer function included in this program is set use
> the generic smtp library
> #   instead of sendmail or procmail.
> #
> #   This is a design decision since the program is intended
> primarily to run
> #   on a Windows platform.
> #
> #
>
>
> #
> #
> #
> #
> def usage():
>   print
> """
> usage: test_orig.py [options]
>
> options:
>   -h, --helpshow this help message and exit
>   -mQMANAGER, --qmanager=QMANAGER
> Queue Manager to inquire against
>   -sHOST, --server=HOST
> Host the que manager resides on
>   -cCHECK, --check=CHECK
> Test object if it is
> less/equal/greater
>   -pPORT, --port=PORT   Port queue manager listens on
>   -oOBJECT, --object=OBJECT
> Queue object being inquired on
>   -kKEY, --key=KEY  object attribute to be inquired
> about
>   -tMTO, --to=MTO   e-mail address the report will go to
>   -q, --quiet   optional - just returns the value
>   -fFILE, --file=FILE   Pull command strings from FILE
>   -d, --display optional - use sends output to
> e-mail
>  """
>
>
> #
> # Trap signal interrupts if they occur
> #
> def signal_handler(signal, frame):
> print 'Signal trapped %s' % signal
> sys.exit(0)
>
>
> #
> # Read a file into a list
> #
> def use_file():
>   myfile = open(options.filename)
>   while True:
>   line=myfile.readline()
>   print line
>   if len(line) == 0:
>   myfile.close()
>   break
>   else:
>   return line
>   myfile.close()
>
>
>
> def check_params():
> if options.report is not None:
>   if options.mto is None:
>   print "\nAsked to send via e-mail but no destination 
> address supplied"
>   usage()
>   sys.exit(1)
> if options.key is None:
>   print"\n\nPlease enter a valid key to inquire upon.\n\nPlease check
> your options and try again"
>   usage()
>   sys.exit(1)
>
> if ( options.port <="1414" ) or ( options.port >="1419" ):
>   print "\n\nAn invalid port number was used. \nValid port numbers
> are 1415,1416,1417, and 1418."
>   print "\nPlease check the port number and try again"
>   usage()
>   sys.exit(1)
>
> #
> #
> # Test return value
> #
> def testval(inc,value):
>   vallen = int(value)
>   if vallen > inc :
> return "\nless than test value\n"
>   elif vallen < inc :
>   return "\nexceeds test value\n"
>   else:
>   return "\nequal to test value\n"
>
>
> # Validate e-mail addresses based on lexical rules set forth in RFC 822
> # Ported from Recipe 3.9 in Secure Programming Cookbook for C and C++ by
> # John Viega and Matt Messier (O'Reilly 2003)
> #
> # If the supplied email address is syntactically valid, isAddressValid()
> # will return 1; otherwise, it will return 0.
> #
> def isAddressValid(addr):
>   #
> # First we validate the name portion ([EMAIL PROTECTED])
> #
> c = 0
> 

Re: GUIs - A Modest Proposal

2010-06-16 Thread Matt

On 06/05/2010 09:22 PM, ant wrote:


 PyQt is tied to one platform.



Several posters have asked for support for or clarification of this 
claim of yours.


On its face it seems to be nonsense.

So just what are you talking about?
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs - A Modest Proposal

2010-06-18 Thread Matt

On 06/17/2010 08:50 AM, Grant Edwards wrote:

On 2010-06-16, Matt  wrote:

On 06/05/2010 09:22 PM, ant wrote:


 PyQt is tied to one platform.


Several posters have asked for support for or clarification of this 
claim of yours.


Let me guess...

The one platform it's tied to is Qt?



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


Re: Multi-Threading and KeyboardInterrupt

2009-06-15 Thread Matt
I'm going to use the multipocessing library from here forward so I can  
take advantage of multiple cores and clusters. Either one should work  
for my use, since in my non-demonstration code each thread spends most  
of it's time waiting for a separate non-Python subprocess (created  
with subprocess.Popen) to finish anyway. (I guess Python would see  
this as IO-blocking) Therefore, if you can fix my toy example with  
threading, that's fine.


DB.py, followed by a KeyboardInterrupt yields the output in a.out. I  
want roughly the output in desired.out.


What do I need to do to modify this code to get my desired output and  
corresponding functionality? It would be a shame if this wasn't  
possible in any pure-Python way.


~Matt

On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote:


On Mon, 15 Jun 2009 05:37:14 -0700 (PDT)
OdarR  wrote:


On 13 juin, 07:25, Mike Kazantsev  wrote:
There was quite interesting explaination of what happens when you  
send

^C with threads, posted on concurrency-sig list recently:

 http://blip.tv/file/2232410
 http://www.dabeaz.com/python/GIL.pdf

Can be quite shocking, but my experience w/ threads only confirms  
that.


Hi there,
please read this package page (in 2.6), this is very interesting.
http://docs.python.org/library/multiprocessing.html

I tested it : it works. Multi-core cpu's are happy :-)


I'd certainly prefer using processes because they indeed work
flawlessly in that respect, but threads are way simplier and much more
integrated into the language, so I can avoid re-imlementing tons of
shared stuff, IPC and locking by using threads which bassically run in
the same context.
That might mean 90% of code for trivial but parallel task.

Alas, they don't work flawlessly in all cases, but there is still
million and one use for them.

--
Mike Kazantsev // fraggod.net
--
http://mail.python.org/mailman/listinfo/python-list
I'm going to use the multipocessing library from here forward so I can  
take advantage of multiple cores and clusters. Either one should work  
for my use, since in my non-demonstration code each thread spends most  
of it's time waiting for a separate non-Python subprocess (created  
with subprocess.Popen) to finish anyway. (I guess Python would see  
this as IO-blocking) DB.py, followed by a KeyboardInterrupt yields the  
output in a.out. I want roughly the output in desired.out.


What do I need to do to modify this code to get my desired output and  
corresponding functionality? It would be a shame if this wasn't  
possible in any pure-Python way.


~Matt

On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote:


On Mon, 15 Jun 2009 05:37:14 -0700 (PDT)
OdarR  wrote:


On 13 juin, 07:25, Mike Kazantsev  wrote:
There was quite interesting explaination of what happens when you  
send

^C with threads, posted on concurrency-sig list recently:

http://blip.tv/file/2232410
http://www.dabeaz.com/python/GIL.pdf

Can be quite shocking, but my experience w/ threads only confirms  
that.


Hi there,
please read this package page (in 2.6), this is very interesting.
http://docs.python.org/library/multiprocessing.html

I tested it : it works. Multi-core cpu's are happy :-)


I'd certainly prefer using processes because they indeed work
flawlessly in that respect, but threads are way simplier and much more
integrated into the language, so I can avoid re-imlementing tons of
shared stuff, IPC and locking by using threads which bassically run in
the same context.
That might mean 90% of code for trivial but parallel task.

Alas, they don't work flawlessly in all cases, but there is still
million and one use for them.

--
Mike Kazantsev // fraggod.net
--
http://mail.python.org/mailman/listinfo/python-list


a.out
Description: Binary data


desired.out
Description: Binary data
#!/usr/bin/env python

import sys, time

try:
	while True:
		pass
except KeyboardInterrupt:
	print '* keyboard int %s ' % sys.argv[1]
	raise#!/usr/bin/env python

from subprocess			import Popen
from multiprocessing	import Process, Semaphore

MAX_SUBPROCS	= 3
RUN_PERMISSION	= Semaphore(MAX_SUBPROCS)

def runSingle(i):
	with RUN_PERMISSION:
		Popen(['./Sub.py', str(i)]).wait()
		
def runAll():
	workers = [ Process(target = runSingle, name = str(i), args = [i])
			for i in xrange(MAX_SUBPROCS + 1) ]
	try:
		for w in workers:
			w.start()
		for w in workers:
			w.join()
	except KeyboardInterrupt:
		## I want this to be all that is shown on a KeyboardInterrupt
		print '* stopped midway '
			
runAll()-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help for using multiprocessing and subprocess packages for creating child processes

2009-06-16 Thread Matt
Try replacing:
cmd = [ "ls /path/to/file/"+staname+"_info.pf" ]
with:
cmd = [ “ls”, “/path/to/file/"+staname+"_info.pf" ]

Basically, the first is the conceptual equivalent of executing the
following in BASH:
‘ls /path/to/file/FOO_info.pf’
The second is this:
‘ls’ ‘/path/to/file/FOO_info.pf’

The first searches for a command in your PATH named ‘ls /path...’. The
second searches for a command names ‘ls’ and gives it the argument
‘/path...’

Also, I think this is cleaner (but it’s up to personal preference):
cmd = [ "ls", "/path/to/file/%s_info.pf" % staname]


~Matthew Strax-Haber
Northeastern University, CCIS & CBA
Co-op, NASA Langley Research Center
Student Government Association, Special Interest Senator
Resident Student Association, SGA Rep & General Councilor
Chess Club, Treasurer
E-mail: strax-haber.m=AT=neu.edu

On Tue, Jun 16, 2009 at 3:13 PM, Rob Newman wrote:
> Hi All,
>
> I am new to Python, and have a very specific task to accomplish. I have a
> command line shell script that takes two arguments:
>
> create_graphs.sh -v --sta=STANAME
>
> where STANAME is a string 4 characters long.
>
> create_graphs creates a series of graphs using Matlab (among other 3rd party
> packages).
>
> Right now I can run this happily by hand, but I have to manually execute the
> command for each STANAME. What I want is to have a Python script that I pass
> a list of STANAMEs to, and it acts like a daemon and spawns as many child
> processes as there are processors on my server (64), until it goes through
> all the STANAMES (about 200).
>
> I posted a message on Stack Overflow (ref:
> http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro) and
> was recommended to use the multiprocessing and subprocess packages. In the
> Stack Overflow answers, it was suggested that I use the process pool class
> in multiprocessing. However, the server I have to use is a Sun Sparc (T5220,
> Sun OS 5.10) and there is a known issue with sem_open() (ref:
> http://bugs.python.org/issue3770), so it appears I cannot use the process
> pool class.
>
> So, below is my script (controller.py) that I have attempted to use as a
> test, that just calls the 'ls' command on a file I know exists rather than
> firing off my shell script (which takes ~ 10 mins to run per STANAME):
>
> #!/path/to/python
>
> import sys
> import os
> import json
> import multiprocessing
> import subprocess
>
> def work(verbose,staname):
>  print 'function:',staname
>  print 'parent process:', os.getppid()
>  print 'process id:', os.getpid()
>  print "ls /path/to/file/"+staname+"_info.pf"
>  # cmd will eventually get replaced with the shell script with the verbose
> and staname options
>  cmd = [ "ls /path/to/file/"+staname+"_info.pf" ]
>  return subprocess.call(cmd, shell=False)
>
> if __name__ == '__main__':
>
>  report_sta_list = ['B10A','B11A','BNLO']
>
>  # Print out the complete station list for testing
>  print report_sta_list
>
>  # Get the number of processors available
>  num_processes = multiprocessing.cpu_count()
>
>  print 'Number of processes: %s' % (num_processes)
>
>  print 'Now trying to assign all the processors'
>
>  threads = []
>
>  len_stas = len(report_sta_list)
>
>  print "+++ Number of stations to process: %s" % (len_stas)
>
>  # run until all the threads are done, and there is no data left
>  while len(threads) < len(report_sta_list):
>
>    # if we aren't using all the processors AND there is still data left to
>    # compute, then spawn another thread
>
>    print "+++ Starting to set off all child processes"
>
>    if( len(threads) < num_processes ):
>
>      this_sta = report_sta_list.pop()
>
>      print "+++ Station is %s" % (this_sta)
>
>      p = multiprocessing.Process(target=work,args=['v',this_sta])
>
>      p.start()
>
>      print p, p.is_alive()
>
>      threads.append(p)
>
>    else:
>
>      for thread in threads:
>
>        if not thread.is_alive():
>
>          threads.remove(thread)
>
> However, I seem to be running into a whole series of errors:
>
> myhost{rt}62% controller.py
> ['B10A', 'B11A', 'BNLO']
> Number of processes: 64
> Now trying to assign all the processors
> +++ Number of stations to process: 3
> +++ Starting to set off all child processes
> +++ Station is BNLO
>  True
> +++ Starting to set off all child processes
> +++ Station is B11A
> function: BNLO
> parent process: 22341
> process id: 22354
> ls /path/to/file/BNLO_info.pf
>  True
> function: B11A
> parent process: 22341
> process id: 22355
> ls /path/to/file/B11A_info.pf
> Process Process-1:
> Traceback (most recent call last):
>  File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in
> _bootstrap
>    self.run()
>  File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run
>    self._target(*self._args, **self._kwargs)
>  File "controller.py", line 104, in work
>    return subprocess.call(cmd, shell=False)
>  File "/opt/csw/lib/python/s

Re: Unable to get Tkinter menubar to appear under OS X

2009-07-17 Thread Matt
same problem on OS 10.4, menu doesn't show up on either from tkinter
or wxpython, continuing search..
-- 
http://mail.python.org/mailman/listinfo/python-list


execute shell script from python, needs sys.argv

2010-11-04 Thread Matt
Hi All,

I am trying to execute a shell script from within python..  This shell
script takes the format, where $1 and $2 are variables from the
command line: cat $1 | Fastx_trimmer -n COUNT -o $2

straight into the cmd line it would be:  cat file.1 | Fastx_trimmer -n
COUNT -o file.2

So,  know that there is a way to do this in python using the
subprocess module, but despite a lot of effort, I can't seem to get
this to work, and precisely because of those arguments taken from the
command line.

I was thinking that the easiest thing to so was to

import sys, os, subprocess
proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o
sys.argv[2]], shell=True)

this clearly does not work...

alternatively, I could put the shell command in its own file, say
fastx.sh, and pass it's arguments to it vie the command line.

import sys, os, subprocess
proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]],
shell=True)

But, this does not seem to work as this is not the proper way to pass
arguments to the shell script.

in short, I'm sure that this is a easy fix, but given my still limited
python vocabulary, it eludes me.

Thanks, Matt


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


SNMP

2017-03-23 Thread Matt
What is easiest way to read and write SNMP values with Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


net-snmp-python

2017-04-01 Thread Matt
Does anyone have an example of using netsnmp library to do a snmpset
on a snmp v2 device?  I have gotten snmpget to work fine with python I
just cannot get snmpset to work.  I know I have the snmp device
configured correctly with read/write access since I can use snmpset on
the linux(centos7) command line to successfully make changes to the
device.

This is on python 2.7.5 stock version included with Centos 7.

The below works fine to do a snmpwalk but I need to do a snmpset on
different variable.

import netsnmp

oid = netsnmp.Varbind('sysDescr')

result = netsnmp.snmpwalk(oid,
  Version = 2,
  DestHost="localhost",
  Community="public")

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


  1   2   3   4   5   6   7   8   >