Re: [PSF-Community] Python Events in 2017, Need your help.

2017-01-09 Thread Danny Adair
Thanks Stephane,

Kiwi PyCon 2017 will be in Auckland, New Zealand in September - exact
dates and location not yet determined. I'll submit it when they are.

Cheers,
Danny


On Mon, Jan 9, 2017 at 10:54 PM, Stephane Wirtel via PSF-Community
 wrote:
> Dear Community,
>
> For the PythonFOSDEM [1] on 4th and 5th February in Belgium, I would like to
> present some slides with the Python events around the World.  Based on
> https://python.org/events, I have noted that there are missing events, for
> example:
>
> * PyCon Otto: Italy
> * PyCon UK: United Kingdom
> * PyCon CA: Canada
> * PyCon Ireland: Ireland
> * PyCon France: France
>
> Some of these events are not yet announced and I understand they are in the
> second semester, and thus, they don't know the location and the dates,
> excepted for PyCon Otto (April).
>
> In fact, I have noted that we know some big events in the Python community
> (for example: PyCon US and EuroPython) but do you know the others events,
> maybe the local event, PyCon IE, PyCon UK or PyCon IT.
>
> I like to know where there is a PyCon or a Django Conf or a PyData Event.
>
> In fact, I think we can help the Python Community if we submit all the
> events in https://python.org/events.
>
> This page has been created by the PSF and is maintained by some volunteers.
>
> I know this list of events:
> * PyCon Cameroon : 20-23 Jav, Cameroon
> * PythonFOSDEM : 4-5 Feb, Belgium
> * PyCon Colombia : 10-12 Feb, Colombia
> * PyCon Pune : 16-20 Feb, India
> * Swiss Python Summit : 17-18 Feb, Switzerland
> * IrPyCon : 17-18 Feb, Iran
> * PyCon SK : 10-13 Mar, Slovakia
> * Django Europe : 3-8 Apr, Italy
> * PyCon Otto : 6-9 Apr, Italy
> * Python Sudeste : 5-7 Mai, Brazil
> * GeoPython : 8-11 May, Switzerland
> * PyCon US : 17-26 May, USA
> * EuroPython : July, Italy
> * PyCon AU : 3-9 Aug, Australia
> * PyCon UK : September, United Kingdom
> * PyCon CA : November, Canada
> * PyCon Ireland : October, Ireland
> * PyCon FR : October/November, France
>
> And you ?
> Please, could you check on https://www.python.org/events/ , if you are an
> organizer, please add your event.
>
> If you think there is a missing event, please, send me the info via
> [email](mailto:steph...@wirtel.be) or via my [twitter
> account](https://twitter.com/matrixise) and I will add it on my slides.
>
> I would like to present your event.
>
> Thank you so much for your help.
>
> Stephane Wirtel
>
> [1] https://www.python-fosdem.org
>
> --
> Stéphane Wirtel - http://wirtel.be - @matrixise
> ___
> PSF-Community mailing list
> psf-commun...@python.org
> https://mail.python.org/mailman/listinfo/psf-community



-- 
Kind regards,

Danny W. Adair
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Convert Qstring to string in windows

2014-10-16 Thread Danny Yoo
On Thu, Oct 16, 2014 at 8:21 AM, C@rlos  wrote:
>
> I have been tryed to convert a Qstring text to string on python, in linux
> that work fine but in windows when qstring contine á,é,í,ó,ú the converted
> text is not correct, contine extranger characters,
> this qstring text is an url from qdialogtext.
>
> in linux i do for this way:
> pythonstringtext=qstringtext.text().toUtf8.data()
> and it return a python string correctly.


Hi Carlos,

This seems like a question that's very specific to Qt: you may want to
ask on a Qt-Python mailing list.  Tutor is intended for beginner
programmers, and the question you're asking seems a bit specialized
for the intended audience.


In absence of this information, I have to make a few guesses.  My best
guesses so far are that you're working with Qt, which provides its own
Unicode string class:

http://qt-project.org/doc/qt-4.8/qstring.html

Are you using PyQt 4 or PyQt 5, or something else entirely?  Are you
using Python 2 or Python 3?

According to the PyQt5 documentation, it automatically handles the
string conversion:


http://pyqt.sourceforge.net/Docs/PyQt5/gotchas.html#python-strings-qt-strings-and-unicode

and according to the PyQt 4 documentation, it also handles the
conversion automatically for you:

http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qstring

and because the mapping is done by the library, you should not have to
be doing anything on your own end to convert Qstrings to Python
strings.


Yeah, I am not sure what you are doing yet, because the documentation
says that it handles conversions for you.  The fact that you're doing
this manually suggests that you might be doing something unusual.  We
need more information.  But I think you may get better help on a
Qt-specific mailing list; I suspect very few of us here have Qt
experience.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: regular expression

2011-08-16 Thread Danny Wong (dannwong)
Thanks chris. I had similar code to what you provided. I included the "#" (it 
was a comment in my code) as part of the string when it shouldn't be as part of 
my test. As soon as you pointed it out that the #'s aren't supposed to be part 
of the output, I removed them and it worked. How dumb of me. Thanks again.

-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Tuesday, August 16, 2011 12:26 AM
To: Danny Wong (dannwong)
Cc: python-list@python.org
Subject: Re: regular expression

On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong)
 wrote:
> Hi All,
>        If I get multiline standard output from a command. How can I
> retrieve this part of the string "(1006)"
> Example:
>
> #Committing...
> #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0"
> #  Component: (1005) "he-Group" <-> (1004) "OS_8.12.0"
> #    Outgoing:
> #      Change sets:
> #        (1006)  *--@  
> #          Changes:
> #            ---c- /he-Group/o-PI/target/config/common-ngp/makefile

Assuming the #s aren't in the actual output:

import re
pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE)
print(pat.search(your_str).group(1))

Obviously can vary depending on how you want to go about defining the
target string.

Cheers,
Chris

P.S. If you reply, please remove my email addresses from the quotation
due to "On Behalf Of" brokenness.
--
Freakin' Outlook/Exchange, I'm telling ya...
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess.Popen question

2011-08-16 Thread Danny Wong (dannwong)
Hi All,
I'm executing a command which I want to capture the
standard/stderr output into a file (which I have with the code below),
but I also want the standard output to go into a variable so I can
process the information for the next command. Any ideas? Thanks.

CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE,
stderr=subprocess.STDOUT)


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


regular expression

2011-08-16 Thread Danny Wong (dannwong)
Hi All,
If I get multiline standard output from a command. How can I
retrieve this part of the string "(1006)"
Example:

#Committing...
#Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0"
#  Component: (1005) "he-Group" <-> (1004) "OS_8.12.0"
#Outgoing:
#  Change sets:
#(1006)  *--@  
#  Changes:
#---c- /he-Group/o-PI/target/config/common-ngp/makefile


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


RE: subprocess.Popen and thread module

2011-08-10 Thread Danny Wong (dannwong)
I did read that portion of the doc, then I change it to communicate and it 
still hangs. So I reverted back to "wait" while launching one thread to see if 
I could isolate the problem, but it still hangs regardless of using "wait" or 
"communicate".

-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Tuesday, August 09, 2011 11:53 PM
To: Danny Wong (dannwong)
Cc: python-list@python.org
Subject: Re: subprocess.Popen and thread module

> On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong)
>  wrote:
>> Hi All,
>>   I'm trying to execute some external commands from multiple database.
>> I'm using threads and subprocess.Popen ( from docs, all the popen*
>> functions are deprecated and I was told to use subprocess.Popen) to
>> execute the external commands in parallel, but the commands seems to
>> hang.
>
> What's your Popen() call look like?

On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong)
 wrote:
>    try:
>        cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', 
> nickname, '-d', directory, project], stdout=subprocess.PIPE, 
> stderr=subprocess.PIPE)
>        status = cmd_output.wait()

Er, did you read the warning about Popen.wait() in the docs? (emphasis added):
"""
Popen.wait()
Wait for child process to terminate. Set and return returncode attribute.
Warning: ***This will deadlock*** when using stdout=PIPE and/or
stderr=PIPE and the child process generates enough output to a pipe
such that it blocks waiting for the OS pipe buffer to accept more
data. Use communicate() to avoid that.
"""
– http://docs.python.org/library/subprocess.html#subprocess.Popen.wait

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: subprocess.Popen and thread module

2011-08-09 Thread Danny Wong (dannwong)
Hi Chris,
Here is the code,
try:
cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', 
nickname, '-d', directory, project], stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
status = cmd_output.wait()
print "In load status is: %s" % status + "\n"
except:
print "Error Executing %s" % command + "\n"


-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Tuesday, August 09, 2011 11:47 PM
To: Danny Wong (dannwong)
Cc: python-list@python.org
Subject: Re: subprocess.Popen and thread module

On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong)
 wrote:
> Hi All,
>   I'm trying to execute some external commands from multiple database.
> I'm using threads and subprocess.Popen ( from docs, all the popen*
> functions are deprecated and I was told to use subprocess.Popen) to
> execute the external commands in parallel, but the commands seems to
> hang.

What's your Popen() call look like?

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess.Popen and thread module

2011-08-09 Thread Danny Wong (dannwong)
Hi All,
   I'm trying to execute some external commands from multiple database.
I'm using threads and subprocess.Popen ( from docs, all the popen*
functions are deprecated and I was told to use subprocess.Popen) to
execute the external commands in parallel, but the commands seems to
hang. 
My question is:
Is subprocess.Popen thread safe?  If not, what other module should I use
to perform a system call? I also, want to log stdout and stderr to a
file. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


python module to determine if a machine is idle/free

2011-08-03 Thread Danny Wong (dannwong)
Hi all,

I have 5 server machines that are using to process
information. I would like to write a quick server python script that
determines which of the machines are not in use. Any recommendations on
which python module I should use to detect if a machine is not
performing idle (ex. Some specific task is not running)?

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


Seeking an example on using Queue to update variable while threading

2011-07-27 Thread Danny Wong (dannwong)
Hi Python experts,
I'm trying to use a dict structure to store and update information from 
X number of threads. How do I share this dict structure between threads? I 
heard of using a queue, but I'm not familiar with how it works. Does anyone 
have an example of using a queue to store variables/dicts between threads?

Thanks

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


virtualenv problem on win32

2011-04-13 Thread Danny Shevitz
Howdy,

I'm trying to use virtualenv for the first time and having endless grief. 
I have upgraded my python distribution to the latest 2.7 distribution and it
is completely clean. I have prepended my path environment variable with
c:\python27 and c:\python27\scripts. 
I have installed:
setuptools 0.6c11 
virtualenv 1.6 
windows extensions (I have read some posts that this might be important...)

When I try to create a virtual environment at the shell prompt:
virtualenv ENV

I get the following error:

###
d:\>virtualenv ENV
New python executable in ENV\Scripts\python.exe
Installing setuptools
  Complete output from command d:\ENV\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])






" c:\python27\lib\site...ols-0.6c11-py2.7.egg:
  Processing setuptools-0.6c11-py2.7.egg
creating d:\env\lib\site-packages\setuptools-0.6c11-py2.7.egg
Extracting setuptools-0.6c11-py2.7.egg to d:\env\lib\site-packages
Traceback (most recent call last):
  File "", line 279, in 
  File "", line 240, in main
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1712, in main
with_ei_usage(lambda:
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1700, in with_ei_usage
return f()
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1716, in 
distclass=DistributionWithoutHelpCommands, **kw
  File "c:\python27\Lib\distutils\core.py", line 152, in setup
dist.run_commands()
  File "c:\python27\Lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
  File "c:\python27\Lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
211, in run
self.easy_install(spec, not self.no_deps)
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
427, in easy_install
return self.install_item(None, spec, tmpdir, deps, True)
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
476, in install_item
dists = self.install_eggs(spec, download, tmpdir)
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
619, in install_eggs
return [self.install_egg(dist_filename, tmpdir)]
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
693, in install_egg
(os.path.basename(egg_path),os.path.dirname(destination)))
  File "c:\python27\Lib\distutils\cmd.py", line 349, in execute
util.execute(func, args, msg, dry_run=self.dry_run)
  File "c:\python27\Lib\distutils\util.py", line 401, in execute
func(*args)
  File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
996, in unpack_and_compile
unpack_archive(egg_path, destination, pf)
  File "c:\python27\lib\site-packages\setuptools\archive_util.py", line 67, in u
npack_archive
driver(filename, extract_dir, progress_filter)
  File "c:\python27\lib\site-packages\setuptools\archive_util.py", line 135, in
unpack_zipfile
z = zipfile.ZipFile(filename)
  File "c:\python27\Lib\zipfile.py", line 712, in __init__
self._GetContents()
  File "c:\python27\Lib\zipfile.py", line 746, in _GetContents
self._RealGetContents()
  File "c:\python27\Lib\zipfile.py", line 786, in _RealGetContents
raise BadZipfile, "Bad magic number for central directory"
zipfile.BadZipfile: Bad magic number for central directory

...Installing setuptools...done.
Traceback (most recent call last):
  File "c:\python27\scripts\virtualenv-script.py", line 8, in 
load_entry_point('virtualenv==1.6', 'console_scripts', 'virtualenv')()
  File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 745, in main
prompt=options.prompt)
  File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 843, in create_environment
install_setuptools(py_executable, unzip=unzip_setuptools)
  File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 571, in install_setuptools
_install_req(py_executable, unzip)
  File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 547, in _install_req
cwd=cwd)
  File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 813, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command d:\ENV\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])

" c:\python27\lib\site...ols-0.6c11-py2.7.egg failed with error code 1
###

does anyone know what is going on?

thanks,
Danny

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


calling 64 bit routines from 32 bit matlab on Mac OS X

2011-03-15 Thread Danny Shevitz
Howdy,

I have run into an issue that I am not sure how to deal with, and would
appreciate any insight anyone could offer.

I am running on Mac OS X 10.5 and have a reasonably large tool chain including
python, PyQt, Numpy... If I do a "which python", I get "Mach-O executable i386".

I need to call some commercial 3rd party C extension code that is 64 bit. Am I
just out of luck or is there something that I can do?

thanks,
Danny

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


Re: attach to process by pid?

2011-03-09 Thread Danny Shevitz

> Have a look at the SIMPL toolkit. 
http://www.icanprogram.com/06py/lesson1/lesson1.html
> 
> This should be able to do exactly what you want.
> 
> bob

Does this work on Mac OS X?

thanks,
Danny 




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


Re: attach to process by pid?

2011-03-09 Thread Danny Shevitz

> process has some kind of communication(s) interface; eg:
>  * some kind of listening socket
>  * some kind of I/O (pipe, stdin/stdout)

It does have a stdin/stdout. How do I access it?

thanks,
D



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


attach to process by pid?

2011-03-08 Thread Danny Shevitz
Howdy,

Is there any way to attach to an already running process by pid? I want to send
commands from python to an application that is already running. I don't want to
give the command name to subprocess.Popen. 

thanks,
Danny

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


Re: how to communicate in python with an external process

2011-03-07 Thread Danny Shevitz

> 
> http://pypi.python.org/pypi/pymatlab/
> 
> Cheers,
> Chris

I am on a mac. Does pymatlab support mac's? I tried the linux 64 bit egg
(downloaded to my local machine) and got:

macshevitz:~ dannyshevitz$ sudo easy_install pymatlab-0.1.3-py2.6-linux-x86_64.
egg
Password:
Searching for pymatlab-0.1.3-py2.6-linux-x86-64.egg
Reading http://pypi.python.org/simple/pymatlab-0.1.3-py2.6-linux-x86_64.egg/
No local packages or download links found for pymatlab-0.1.3-py2.6-linux-
x86-64.egg
error: Could not find suitable distribution for
Requirement.parse('pymatlab-0.1.3-py2.6-linux-x86-64.egg')

I am in the same directory as the egg when I do this. I am certainly doing
something stupid, but don't know what it is.

thanks,
Danny





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


how to communicate in python with an external process

2011-03-07 Thread Danny Shevitz
Howdy,

I'm a long time python user but ran across something I have never needed to do
before and don't know how to do it. 

The issue is that I need for my python script to call some matlab routines.
Matlab is very expensive to start running, so I only want to run it once. I also
want the changes I make in one call to matlab persist to the next call to 
matlab.

I don't know how to do this. What I want to do is something like create a matlab
process, get it's pid and then attach later (this can be in blocking mode) to 
that pid to execute the command, read the output, then go on in my python code
and at some point later, repeat the process of attaching to the persistent
matlab pid...

I am familiar with subprocess.Popen, but I don't understand how to attach to a
pid, as opposed to creating a new matlab instance every time.

Any enlightenment would be appreciated.

thanks,
Danny

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


Re: Debugger - fails to "continue" with breakpoint set

2010-09-27 Thread Danny Levinson

 Does this describe the problem you are having?

http://bugs.python.org/issue5294

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


Re: IOError and Try Again to loop the loop.

2010-07-11 Thread The Danny Bos


Thanks Chris,

Agreed some of the code is a lot useless, I need to go through that
stuff.
So something like this (apologies for asking for some details, I'm not
good at catching):

items = Item.objects.all().filter(cover='').order_by('-reference_id')
for item in items:
url = "http://someaddress.org/books/?issue=%s"; %
item.reference_id
url_array = []
url_open = urllib.urlopen(url)
url_read = url_open.read().decode('utf-8')

while True:
try:
url_data = simplejson.loads(url_read)
url_array.append(url_data)
for detail in url_array:
if detail['artworkUrl']:
cover_url =
detail['artworkUrl'].replace(' ','%20')
cover_open =
urllib.urlretrieve(cover_url)
cover_name = os.path.split(cover_url)
[1]
item.cover.save(cover_name,
File(open(cover_open[0])), save=True)
print "Cover - %s: %s" % (item.number,
url)
else:
print "Missing - %s: %s" %
(item.number, url)
break
except ValueError:
print "Error Processing record: %s: %s" %
(item.reference_id, url)
pass
except IOError:
print "IOError; Retrying..."
pass

print "Done"




On Jul 12, 2:14 pm, Chris Rebert  wrote:
> On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos  wrote:
>
>
>
>
>
> > Thanks gang,
> > I'm gonna paste what I've put together, doesn't seem right. Am I way
> > off?
>
> > Here's my code.
> >  - It goes through a table Item
> >  - Matches that Item ID to an API call
> >  - Grabs the data, saves it and creates the thumbnail
> >  - It dies due to Timeouts and Other baloney, all silly, nothing code
> > based.
>
> > items = Item.objects.all().filter(cover='').order_by('-reference_id')
> > for item in items:
> >        url = "http://someaddress.org/books/?issue=%s"; % item.reference_id
>
> >        url_array = []
> >        url_open = urllib.urlopen(url)
> >        url_read = url_open.read().decode('utf-8')
>
> >        try:
> >                url_data = simplejson.loads(url_read)
> >                url_array.append(url_data)
>
> >                for detail in url_array:
>
> Unless I'm missing something, there's no need for url_array to exist
> at all. It starts out empty, you append url_data to it, then you
> iterate over it as `detail`; and you don't touch it anywhere else in
> the loop. Just s/detail/url_data/ and excise url_array altogether. As
> a bonus, there'll be one less level of indentation.
>
> Also, the reason your code doesn't work (currently, it just skips to
> the next item upon error) is because you're missing a surrounding
> `while True` loop (and associated embedded `break`) to do the retrying
> (see my or MRAB's examples).
>
> Additionally, stylistically I'd prefer the try-excepts to cover
> smaller and more targeted areas of the code, rather than having one
> giant blanket one for the entire loop body; perhaps that's just me
> though.
>
> Cheers,
> Chris
> --
> How exactly does one acquire a prenominal "The"?http://blog.rebertia.com

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


Re: IOError and Try Again to loop the loop.

2010-07-11 Thread The Danny Bos
Thanks gang,
I'm gonna paste what I've put together, doesn't seem right. Am I way
off?

Here's my code.
 - It goes through a table Item
 - Matches that Item ID to an API call
 - Grabs the data, saves it and creates the thumbnail
 - It dies due to Timeouts and Other baloney, all silly, nothing code
based.

items = Item.objects.all().filter(cover='').order_by('-reference_id')
for item in items:
url = "http://someaddress.org/books/?issue=%s"; % item.reference_id

url_array = []
url_open = urllib.urlopen(url)
url_read = url_open.read().decode('utf-8')

try:
url_data = simplejson.loads(url_read)
url_array.append(url_data)

for detail in url_array:
if detail['artworkUrl']:
cover_url = detail['artworkUrl'].replace(' 
','%20')
cover_open = urllib.urlretrieve(cover_url)
cover_name = os.path.split(cover_url)[1]

item.cover.save(cover_name, 
File(open(cover_open[0])),
save=True)## Create and save Thumbnail

print "Cover - %s: %s" % (item.number, url)
else:
print "Missing - %s: %s" % (item.number, url)

except ValueError:
print "Error Processing record: %s: %s" % (item.reference_id, 
url)
pass
except IOError:
print "IOError; Retrying..."
pass

print "Done"



On Jul 12, 12:33 pm, MRAB  wrote:
> The Danny Bos wrote:
> > Heya,
>
> > I'm running a py script that simply grabs an image, creates a
> > thumbnail and uploads it to s3. I'm simply logging into ssh and
> > running the script through Terminal. It works fine, but gives me an
> > IOError every now and then.
>
> > I was wondering if I can catch this error and just get the script to
> > start again?
> > I mean, in Terminal it dies anyway, so I have to start it again by
> > hand, which is a pain as it dies so sporadically. Can I automate this
> > error, catch it and just get it to restart the loop?
>
> > Thanks for your time and energy,
>
> Exceptions can be caught. You could do something like this:
>
>      while True:
>          try:
>              do_something()
>              break
>          except IOError:
>              pass

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


IOError and Try Again to loop the loop.

2010-07-11 Thread The Danny Bos
Heya,

I'm running a py script that simply grabs an image, creates a
thumbnail and uploads it to s3. I'm simply logging into ssh and
running the script through Terminal. It works fine, but gives me an
IOError every now and then.

I was wondering if I can catch this error and just get the script to
start again?
I mean, in Terminal it dies anyway, so I have to start it again by
hand, which is a pain as it dies so sporadically. Can I automate this
error, catch it and just get it to restart the loop?

Thanks for your time and energy,

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


Re: MODULE FOR I, P FRAME

2010-02-24 Thread DANNY
On Feb 24, 3:11 am, "Rhodri James" 
wrote:
> On Tue, 23 Feb 2010 10:39:21 -, DANNY  wrote:
> > @James I am thinkinhg about effect of errors that are within the
> > sequence of P frames. Where the P frames have only the information
> > about the changes in previous frames, so that errors are present until
> > the next Iframe. So I would like to see how is this seen in different
> > GoP sized clips.
>
> Ah, I see.  What I'd suggest you do is to encode your video clip at  
> various GOP sizes (you'll want some quite extreme ones for comparison),  
> then write a little program that reads in the file byte by byte and  
> randomly corrupts the data as it goes through.  "tsplay" from the tstools  
> suite that I mentioned earlier will do that for you (because it was very  
> handy for testing the robustness of our decoders).  Then watch the results  
> using VLC or similar.
>
> My recollection is that when the image isn't static, P frames tend to have  
> enough intra-coded blocks that corrupted video data doesn't have as much  
> effect as you might think.  I've dealt with streams that had ten seconds  
> or more between I frames, and starting at a random spot (simulating  
> changing channel on your digital TV) builds up an intelligible (if  
> obviously wrong) image surprisingly quickly.
>
> PS: my first name is Rhodri, not James.  Don't worry, it catches a lot of  
> people out.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

Well for my simulation of errors I am thinking on using the WANem
(Wide Area Netwrok Emulator) which has a function to simulate dellay,
jitter etc.. http://wanem.sourceforge.net/
I have been downloading the clips from youtube and I surprisengly saw
that I frame occures after 300 frames(at 15fps-so that means after 20
seconds)! That was quite unusal for my perception of the purpose of I
frame, but then I figured out that (as you mentioned) P frames include
intra-coded blocks which hide the effect of the errors.

The goal of my project is to make a program which plays the corrupted
video after being out thru error concealment, and in case when errors
overcome some threshold error value the program doesn't paly any more
frames until the I frame occures and then I would figure out the
optimal threshold value for the different GoP sizes as well as
different content of the clip.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MODULE FOR I, P FRAME

2010-02-23 Thread DANNY
@James I am thinkinhg about effect of errors that are within the
sequence of P frames. Where the P frames have only the information
about the changes in previous frames, so that errors are present until
the next I frame. So I would like to see how is this seen in different
GoP sized clips.

@Tim Thanks for the advice, now I will try to do that so I have a lot
of work in front of me. I will post any problems if they occure.

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


Re: MODULE FOR I, P FRAME

2010-02-22 Thread DANNY
On Feb 21, 1:54 am, Tim Roberts  wrote:
> DANNY  wrote:
>
> >If I want to have a MPEG-4/10 coded video and stream it through the
> >network and than have the same video on the client side, what should I
> >use and of course I don't want to have raw MPEG data, because than I
> >couldn't extract the frames to manipulate them.
>
> If you want to manipulate the frames (as bitmaps), then you have little
> choice but to decode the MPEG as you receive it, manipulate the bitmaps,
> and re-encode it back to MPEG.
>
> That's going to take a fair amount of time...
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Yes, well beside bieng time-consuming, that is also inappropriate for
me,
because I want to have clip that would be streamed across the network
and
have the same GoP on the client side as the original-because I want to
see
what is the effect of errors on different GoP sizes. I would
manipuleta the
received clip just in the way that (if there are too many errors) I
would
stop displaying untill the next I frame.I cant find a way to do
thatis there a way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MODULE FOR I, P FRAME

2010-02-15 Thread DANNY
On Feb 16, 12:53 am, "Rhodri James" 
wrote:
> On Sun, 14 Feb 2010 10:07:35 -, DANNY  wrote:
> > Hy, first thanks for your response!
> > Well I am thinkin on coding in MPEG4/10, but I would just encode the
> > video in that encoding,
> > then stream it with VLC and save the video file on my disc. Then I
> > would play it with my player
>
> I think you're misunderstanding what VLC does here.  Saving the video file  
> should preserve format by default; you may be able save it out in YUV  
> format (I don't have a copy on this machine to check), but that will take  
> up ludicrous amounts of disc space and you'd still have to write a byte  
> reader for it.  If you do do that, you have lost any chance of knowing  
> whether a frame was an I or P frame in the original format, not that it  
> matters anyway by that point.
>
> MPEG-4/10 is hard to write efficient decoders for, and I have to admit I  
> wouldn't do it in Python.  You'd be better off writing a wrapper for one  
> of the existing MP4 libraries.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses


Hm, well I see that and now I am thinking of using reference software
for MPEG4/10 which is written in c++  http://iphome.hhi.de/suehring/tml/
just to use it as a decoder on my client side, save the file in that
format and then play it in my player using pyffmpeg
http://code.google.com/p/pyffmpeg/ and just manipulate frames in that
clip-I think that could be possibleam I right? Thanks for your
help!
-- 
http://mail.python.org/mailman/listinfo/python-list


MODULE FOR I, P FRAME

2010-02-11 Thread DANNY
Hello!

I am currently developing a simple video player in python, and my
problem is that i can't find a module which has a function that can
determine if frame(image) is I or P coded (MPEG coding). I have been
using PIL but I couldnt find anything that could help me with that
problem.

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


geospatial python and how to convert multilinestrings to kml

2009-03-03 Thread Danny Shevitz
Howdy,

I need to do some geospatial work and am a complete newbie at this. I have
access to a PostGIS database and there are lots of MultiLineString objects.
I want to run a python algorithm that determines a group of these 
MultiLineString
objects and creates a KML file of the results. 

Is there a pythonic way (some existing module) to convert PostGIS 
MultiLineStrings to a KML file format?

thanks,
Danny

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


problem doing unpickle in an exec statement

2008-07-23 Thread Danny Shevitz
Howdy, 

In my app I need to exec user text that defines a function. I want this
function to unpickle an object. Pickle breaks because it is looking for
the object definition that isn't in the calling namespace. 

I have mocked up a simple example that shows the problem. Run this 
first code (from create_pickle.py) to create the pickle.

create_pickle.py: (run this first)

#
import cPickle

# the pickle file name
file_name = 'd:\\temp\\test1.pickle'

# define a class
class Tree(object):
pass


def main():
# instantiate   
t = Tree()

# create the sweet pickle
fp = open(file_name, 'wb')
cPickle.dump(t, fp)
fp.close()

# try to unpickle directly
fp = open(file_name, 'rb')
result = cPickle.load(fp)
fp.close()
print "unpickling directly works just fine, result = ", result

if __name__=='__main__':
main()
#

run this second:

exec_pickle.py
#
# this file shows a problem with sweet pickle in an exec statement

# the pickle file name
file_name = 'd:\\temp\\test1.pickle'

# code to be turned into a function
code_text = '''
def include():
  print "this works!"
'''

# a function for creating functions
def create_fun(code_text):
clean_dict = {} 
exec code_text in clean_dict
return clean_dict['include']

# include_fun is a bona fide function
include_fun = create_fun(code_text)

# this works
include_fun()


# now try to load the pickle in an exec statement
code_text = '''
def include(file_name):
  print "processing file_name: ", file_name
  import cPickle
  fp = open(file_name, "rb")
  result = cPickle.load(fp)
  fp.close()
  print "result = ", result
'''

# create the new include_fun
include_fun = create_fun(code_text)

# run it
include_fun(file_name)

#

Can anyone enlighten me what I need to do to exec_pickle.py
to get this to work?

thanks,
Danny

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


Re: how to convert a multiline string to an anonymous function?

2008-04-30 Thread Danny Shevitz
Thanks All!

you've solved my problem.

D

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


how to convert a multiline string to an anonymous function?

2008-04-29 Thread Danny Shevitz
Simple question here:

I have a multiline string representing the body of a function. I have control
over the string, so I can use either of the following:

str = '''
print state
return True
'''

str = '''
def f(state):
  print state
  return True
'''

and I want to convert this into the function:

def f(state):
  print state
  return True

but return an anonmyous version of it, a la 'return f' so I can assign it
independently. The body is multiline so lambda doesn't work.

I sort of need something like:

def function_constructor(str):
  f = eval(str) # What should this be
  return f

functions = {}
for node in nodes:
  function[node] = function_constructor(node.text)

I'm getting stuck because 'def' doesn't seem to work in an eval function,
and exec actually modifies the namespace, so I run into collisions if I use
the function more than once.

I know I'm missing something stupid here, but I'm stuck just the same...

thanks,
Danny

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


instance method questions

2007-08-22 Thread Danny
howdy, 

I have created an instance method for an object using new.instancemethod. It
works great. Now the questions are:

1) how do I dynamically inspect an object to determine if it has an instance
method? (there is a class method with the same name)

2) how do I dynamically delete the instance method?

thanks,
Danny

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


problem with psqlite2 return types

2007-07-18 Thread Danny
Howdy,

I'm having troubles with psqlite2 and the return types from a query. The problem
is that my data which is numeric, is being returned as a string. I'm aware of 
the
detect_types=sqlite.PARSE_DECLTYPES argument to the connect function. 

Here's my connection code:  
self.connection = sqlite.connect(self.dbFile,
detect_types=sqlite.PARSE_DECLTYPES)#
self.connection.text_factory=str
self.cursor = self.connection.cursor()

Here's my sql (I'm returning risk1, which is numeric):
create table risk(
quantity varchar(8),
color varchar(8),
risk1 real,
risk2 real,
primary key (quantity, color)
);

( I have also tried [REAL, float, FLOAT], none work for me)

Here's my query (this will probably be not much use out of context...):
primaryKeys = self.primaryKeyFields[table]
primaryKeyList= ' and '.join(['%s = ?'% pKey for pKey in 
primaryKeys])
query = 'select %s from %s where %s' % (field, table, 
primaryKeyList)
paramList = [state[primaryKey] for primaryKey in primaryKeys]
self.cursor.execute(query, paramList)

Any ideas?

TIA,
Danny

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


Re: Common Python Idioms

2006-12-07 Thread Danny Colligan
> Is there a list somewhere listing those not-so-obvious-idioms?

I don't know about lists of not-so-obvious idioms, but here's some
gotchas (there may be some overlap with what you're asking about):

http://zephyrfalcon.org/labs/python_pitfalls.html
http://www.ferg.org/projects/python_gotchas.html
http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html

Danny

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


Re: IEC Controller and element

2006-11-30 Thread Danny Scaleno
Maybe this help someone else.
The solution comes with old VB6. It's "COM Land" so
introspecting the VB WebBrowser Control object I found properties and 
methods to correctly access all parts of the python IEC.Document object 
returned by the IEC Controller

http://www.mayukhbose.com/python/IEC/index.php

Great library !
Danny

> using IEC Controller,
> anybody knows how to capture the head part of an html page like this one?
> 
> 
> 
> 
> Object=window.open('test.html','test1','name="test1"');
> Object.focus()
> 
> 
> 
> 
 > it seems IEC is able to capture only the  part.
 > I need to parse the string inside the tag 

IEC Controller and element

2006-11-28 Thread Danny Scaleno
Hello,

using IEC Controller,
anybody knows how to capture the head part of an html page like this one?




Object=window.open('test.html','test1','name="test1"');
Object.focus()





it seems IEC is able to capture only the  part.
I need to parse the string inside the tag 

Re: Yield

2006-11-16 Thread Danny Colligan
> The more trivial the example, the harder it is to see the advantage.

I absoultely agree.  Thanks for pointing me out to some real-world
code.  However, the function you pointed me to is not a generator
(there is no yield statement... it just returns the entire list of
primes).  A generator version would be:

>>> def primes(n):
... if n<2: yield []
... s=range(3,n+1,2)
... mroot = n ** 0.5
... half=(n+1)/2-1
... i=0
... m=3
... while m <= mroot:
... if s[i]:
... j=(m*m-3)/2
... s[j]=0
... while j>> x = primes(11)
>>> x.next()
2
>>> x.next()
3
>>> x.next()
5
>>> x.next()
7
>>> x.next()
11
>>> x.next()
Traceback (most recent call last):
  File "", line 1, in ?
StopIteration
>>>

Danny Colligan

On Nov 16, 10:49 am, "Richard Brodie" <[EMAIL PROTECTED]> wrote:
> "Danny Colligan" <[EMAIL PROTECTED]> wrote in messagenews:[EMAIL PROTECTED]
>
> > Now that we're on the subject, what are the advantages of using
> > generators over, say, list comprehensions or for loops?  It seems to me
> > that virtually all (I won't say everything) the examples I've seen can
> > be done just as easily without using generators.The more trivial the 
> > example, the harder it is to see the advantage.
> Suppose you wanted to sum the first 1 primes. A quick Google
> fins you Wensheng Wang's 
> recipe:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366178
> Just add print sum(primes(1)), and you're done.

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


Re: Yield

2006-11-16 Thread Danny Colligan
Now that we're on the subject, what are the advantages of using
generators over, say, list comprehensions or for loops?  It seems to me
that virtually all (I won't say everything) the examples I've seen can
be done just as easily without using generators.  For example,
Fredrik's initial example in the post:

>>> a = [1,2,3]
>>> for i in a: print i
...
1
2
3
>>> sum(a)
6
>>> [str(i) for i in a]
['1', '2', '3']
>>>

Carsten mentioned that generators are more memory-efficient to use when
dealing with large numbers of objects.  Is this the main advantage of
using generators?  Also, in what other novel ways are generators used
that are clearly superior to alternatives?

Thanks in advance,

Danny

On Nov 16, 3:14 am, John Machin <[EMAIL PROTECTED]> wrote:
> On 16/11/2006 7:00 PM, Fredrik Lundh wrote:
>
> > John Machin wrote:
>
> >>> I would like to thanks Fredrik for his contribution to improve that.
>
> >> Call me crazy, but after an admittedly quick read, the version on the
> >> wiki seems to be about word for word with on the docs.python.org version.
>
> > maybe he was thinking about the article I posted, or the FAQ link I
> > posted in a followup:
>
> >http://effbot.org/pyfaq/what-is-a-generator.htm
>
> > which was based on my article and the glossary entry from the tutorial:
>
> >http://effbot.org/pytut/glossary.htm#generatorQuite possibly.
>
>
>
> >> Could you please tell us how you think the wiki version is an
> >> improvement?
>
> > an "add comment" link?  direct URL:s for all concepts in the language?
> > extensive hyperlinking?  semantic retargetable markup?Yes, they're great. 
> > Maybe I was thinking about the text contents only :-)
> 
> Cheers,
> John

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


newbie: minidom

2006-11-10 Thread Danny Scalenotti
I'm not able to get out of this ...


from  xml.dom.minidom import getDOMImplementation

impl = getDOMImplementation()  // default UTF-8
doc = impl.createDocument(None, "test",None)
root = doc.documentElement
root.setAttribute('myattrib', '5')

print root.toxml()


I obtain





why not this?





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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
I see.  Thanks for the helpful response.

Danny

Duncan Booth wrote:
> "Danny Colligan" <[EMAIL PROTECTED]> wrote:
>
> > In the following code snippet, I attempt to assign 10 to every index in
> > the list a and fail because when I try to assign number to 10, number
> > is a deep copy of the ith index (is this statement correct?).
>
> No. There is no copying involved.
>
> Before the assignment, number is a reference to the object to which the ith
> element of the list also refers. After the assignment you have rebound the
> variable 'number' so it refers to the value 10. You won't affect the list
> that way.
>
> > My question is, what was the motivation for returning a deep copy of
> > the value at the ith index inside a for loop instead of the value
> > itself?
>
> There is no copying going on. It returns the value itself, or at least a
> reference to it.
>
> >  Also, is there any way to assign to a list in a for loop (with
> > as little code as used above) without using enumerate?
>
> a[:] = [10]*len(a)
>
> or more usually something like:
>
> a = [ fn(v) for v in a ]
>
> for some suitable expression involving the value. N.B. This last form
> leaves the original list unchanged: if you really need to mutate it in
> place assign to a[:] as in the first example, but if you are changing all
> elements in the list then you usually want a new list.

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


Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
In the following code snippet, I attempt to assign 10 to every index in
the list a and fail because when I try to assign number to 10, number
is a deep copy of the ith index (is this statement correct?).

>>> a = [1,2,3,4,5]
>>> for number in a:
... number = 10
...
>>> a
[1, 2, 3, 4, 5]

So, I have to resort to using enumerate to assign to the list:

>>> for i, number in enumerate(a):
... a[i] = 10
...
>>> a
[10, 10, 10, 10, 10]

My question is, what was the motivation for returning a deep copy of
the value at the ith index inside a for loop instead of the value
itself?  Also, is there any way to assign to a list in a for loop (with
as little code as used above) without using enumerate?

Thanks,

Danny

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


Hiding / showing windows in Macs

2006-09-19 Thread Sinang, Danny



Hello,
 
How do we hide and 
show windows in Macs ?
 
Regards,
Danny
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Zipping Files to user defined Directory

2006-09-02 Thread Danny Milosavljevic
Hi,

On Fri, 28 Jul 2006 05:25:38 -0700, OriginalBrownster wrote:

> Marc 'BlackJack' Rintsch wrote:
>> In <[EMAIL PROTECTED]>,
>> OriginalBrownster wrote:
>>
[...]
>> After the user selected the files you have to zip them on the server,
>> for instance in a temporary in the `/tmp/` directory and then deliver
>> that archive to the user.
>>
>> Ciao,
>>  Marc 'BlackJack' Rintsch
> 
> 
> THanks Marc,
> 
> That makes sense. I can zip the files to a temp directory. However, How
> do I deliver the archive to them?...

Like you deliver any other content in a cgi (assuming you are using a cgi):
By printing in on standard output.

I don't know "TurboGears" though.

cheers,
  Danny
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] os listdir access denied when run as a service

2006-05-25 Thread Danny Yoo


On Thu, 25 May 2006, Thomas Thomas wrote:


> I am trying to access a mapped network drive folder. everything works 
> fine normally. But when i run the application as service I am getting 
> the error

The error is on the line:

 for filename in os.listdir(folder):#line 25

and I have to assume that the bad call here is to os.listdir().



What's the particular input that's being sent to os.listdir() at the point 
of failure?  As far as I can tell, the error message:

> Traceback (most recent call last):
>  File "docBoxApp.py", line 129, in ?
>  File "core\PollFiles.pyc", line 332, in doPoll
>  File "core\PollFiles.pyc", line 47, in createFileList
>  File "core\PollFiles.pyc", line 25, in addFolderFiles
> WindowsError: [Errno 5] Access is denied:'G:\\DT Hot Folder test/*.*'

suggests that 'G:\\DT Hot Folder test/*.*' might be the folder being 
passed.  If so, that could be the problem, since os.listdir takes the name 
of a directory: it does not take a file glob.


Can you check to see what 'folder' is being passed into your program in 
the context of a file service?  The problem may simply be bad input.


We can check early on this by programming a bit defensively, mandating 
that on entry to addFolderFiles that 'folder' must be an existing 
directory:


def addFolderFiles(folder, filelist=[]):
 assert os.path.isdir(folder)
 ...


in which case, if we get past the assertion, we'll be able to at least 
know that we're getting in semi-good input.



One other note: it is not recommended that we use a list as a default 
parameter value.  That value will be shared among all calls to 
addFolderFiles, so we will see side effects.  See the "Important Warning" 
in:

http://docs.python.org/tut/node6.html#SECTION00671
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing numbers into characters using dictionaries

2006-01-26 Thread Danny
Hello again,

I am now trying to make something to change some "encrypted" text into 
some plain text, here is the code I have so far:

text = '@[EMAIL PROTECTED]@[EMAIL PROTECTED]' // some text
num = '213654' // Number
s1 = '700'
s2 = '770'
s4 = '707' // it adds these later on.
t = text.split('@') // splits the digits/blocks apart from each other
a = {s2+num[3]:"l", s1+num[0]:"a", s4+num[5]:"w"}

something = 1
while True:
 var = str(a[t[something]])
 print var,
// I want it to change "@[EMAIL PROTECTED]@[EMAIL PROTECTED]" into "lawl"

I get the error:
Traceback (most recent call last):
   File "C:/Documents and Settings/Danny/My 
Documents/python/changetext.py", line 9, in ?
 var = str(a[t[something]])
KeyError: '7704'

I've explained what is needed to happen in the comments. Also, if any of 
you can think of a better way to do this can you possibly tell me this? 
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While loop - print several times but on 1 line.

2006-01-26 Thread Danny
Great! It's been solved.

The line, as Glaudio said has a "," at the end and that makes it go onto 
one line, thanks so much man!

var = 0
while <= 5:
print a[t[var]],
var = var +1
prints perfectly, thanks so much guys.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While loop - print several times but on 1 line.

2006-01-26 Thread Danny
I think I should paste some of the programs code a little more of what I 
want...

var = 0
while var <= 5:
 print a[t[var]]
 var = var +1

a is a dectionary (very big) and t is a string of text. (if that's 
important right now).

I'm just trying to make the value of a[t[var]] print on one line if that 
makes any sense...
Sorry if I'm not explaining this very well and if my examples aren't 
very good, I am trying.
-- 
http://mail.python.org/mailman/listinfo/python-list


While loop - print several times but on 1 line.

2006-01-26 Thread Danny
Hello there.

I'm creating a little text changer in Python. In the program there is a 
while loop. The problem is that a while loop will have 1 print statement 
  and it will loop until it gets to the end of the text.
Example:

num = 5 // Set num to 5
while num >= 1: // loop 5 times.
print """text"""
num = num-1
// end.

The programs output will be:
text
text
(etc)

How could I make this print: texttexttexttexttext?
Ive researched and looked through google and so far I can't find 
anything that will help (or revelent for that matter).

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


Re: [Baypiggies] BayPIGgies: December 8, 7:30pm (IronPort)

2005-12-05 Thread Danny Yoo
> Advance notice:  We need speakers for January and later.  Please send
> e-mail to [EMAIL PROTECTED] if you want to suggest an agenda (or
> volunteer to give a presentation).

Correction: that email address should be '[EMAIL PROTECTED]'.

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


Re: [Tutor] how to convert between type string and token

2005-11-14 Thread Danny Yoo


On Mon, 14 Nov 2005, enas khalil wrote:

> hello all

[program cut]

Hi Enas,

You may want to try talking with NTLK folks about this, as what you're
dealing with is a specialized subject.  Also, have you gone through the
tokenization tutorial in:

http://nltk.sourceforge.net/tutorial/tokenization/nochunks.html#AEN276

and have you tried to compare your program to the ones in the tutorial's
examples?



Let's look at the error message.

>   File "F:\MSC first Chapters\unigramgtag1.py", line 14, in -toplevel-
> for tok in train_tokens: mytagger.train(tok)
>   File "C:\Python24\Lib\site-packages\nltk\tagger\__init__.py", line 324, in 
> train
> assert chktype(1, tagged_token, Token)
>   File "C:\Python24\Lib\site-packages\nltk\chktype.py", line 316, in chktype
> raise TypeError(errstr)
> TypeError:
> Argument 1 to train() must have type: Token
>   (got a str)

This error message implies that each element in your train_tokens list is
a string and not a token.


The 'train_tokens' variable gets its values in the block of code:

###
train_tokens = []
xx=Token(TEXT=open('fataha2.txt').read())
WhitespaceTokenizer().tokenize(xx)
for l in xx:
train_tokens.append(l)
###


Ok.  I see something suspicious here.  The for loop:

##
for l in xx:
train_tokens.append(l)
##

assumes that we get tokens from the 'xx' token.  Is this true?  Are you
sure you don't have to specifically say:

##
for l in xx['SUBTOKENS']:
...
##

The example in the tutorial explicitely does something like this to
iterate across the subtokens of a token.  But what you're doing instead is
to iterate across all the property names of a token, which is almost
certainly not what you want.

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


Re: append one file to another

2005-07-12 Thread Danny Nodal
Its been a while since I last coded in Python, so please make sure you test
it before trying it so you don't clobber your existing file. Although it may
not be more effecient than what you are doing now or has been suggested
already, it sure cuts down on the typing.

open(outfilename,'a').write(open(infilename).read())

Regards.

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I want to append one (huge) file to another (huge) file.  The current
> way I'm doing it is to do something like:
>
> infile = open (infilename, 'r')
> filestr = infile.read()
> outfile = open(outfilename, 'a')
> outfile.write(filestr)
>
> I wonder if there is a more efficient way doing this?
> Thanks.
>


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


Re: cursor positioning

2005-07-11 Thread Danny Milosavljevic
Hi,

On Mon, 11 Jul 2005 15:29:41 +0200, Mage wrote:

>  Dear All,
> 
> I am writing a database import script in python and I would like to
> print the percentage of the process to the last line. I would like to
> update the last line at every percent. You know what I mean.
> 
> How can the cursor be positioned to the last line or somewhere else on
> the screen? Curses starts with clearing the whole screen and it is
> overkill. Many modules are on the net but I would like to resolve this
> simply task with native python.
> 
> I tried:
> 
> for something:
> print chr(8)*20+mystring,
> 
> but it is nasty and didn't work well.
> 
>   Mage

If you only want to support ansi terminals (which is questionable, but
possible), then there are escape codes that are very helpful (searching
for ansi escape codes or something in google should help you find the
remainder):

the general syntax is 

ESC[

action usually is the first letter in the sequence, hence parameters are
usually numbers (duh :))

ESC is chr(27) (ascii 27, octal \033)

actions are
  Hcursor go home (top left corner usually)
  Cgo right  times
  Dgo left   times
  Ago up  times
  Bgo down  times
  Kclear to end of line
  2J   clear screen (yes, to every rule there are exceptions :), note that
this does not make the cursor go home)
  mset color/highlight/formatting flags

Examples
  ESC[2JESC[H   same as "clear", clear screen, go home
  \rESC[Kprogress %dprobably what you want :)

The downside of this is that determining the size of the screen is pretty
hard to do right.

Process is usually, read TERM environment variable, read /etc/termcap
(deprecated) "co" attribute (columns), "li" attribute (rows). That has
been deprecated because of all those resizeable terminals out there. 

Now its something like outputting some magical stuff to make the terminal
emulator send back the current sizes immediately once, and whenever they
change. 
I'm not totally clear how that works since I'm too lazy to care :)

What you want is probably

prc = 0
for prc in range(100):
sys.stderr.write("\r\033[KProgress %d%% ... " % prc) 
sys.stderr.flush()
time.sleep(0.5)

though :)

Note that this can wreck havoc onscreen if the terminal is smaller than what is
needed to print that horizontally, so technically its not totally clean code.

Hope that helps

cheers,
   Danny

  

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


socket.listen() backlog value

2005-03-11 Thread Sinang, Danny



Hello.
 
Most of the socket 
articles I've read say that 5 is the normal value for socket.listen() backlog 
parameter.
 
We're running a 
server (written in Python) with the value set to 10, but during peak 
periods, users complain that their clients (also written in 
Python) "hang".
 
Here's the server 
code :
 
===
 
import osimport 
timeimport stringimport LoginParserimport structfrom socket 
import *import thread
 
class 
Start:
 
    
def startserver(self):
 
    s = socket(AF_INET, 
SOCK_STREAM)    s.bind(('', 
7878))    
s.listen(10)    print 'Login Server 
started on port 7878' 
 
    while 
1:    
client,addr = 
s.accept()    
cl =  "Got a conection from " + 
str(addr)    
print cl    
ipaddress = 
addr[0]    
try:    
msg = 
client.recv(1024).split("~~")    
p = 
LoginParser.Start(msg[0],ipaddress)    
client.send(p.reply)    
except:    
pass    
try:    
client.close()    
except:    
pass
 
 
 
    
def exitprog(self,event):
 
    
sys.exit(0)
 
    
def __init__(self):
 
    
self.startserver()
 

 
The 
LoginParserver.Start ( ... ) queries a database to see if the username, password 
given by the client is valid and returns some pertinent information to the 
client.
 
The server runs 
on a Pentium 4 with 512 MB of memory, running WhiteBox linux and Python 2.2 
.
 
We've got about 
1,000 employees / users all logging on / off during shift change and this is 
when the problems are reported.
 
My question is, is 
our socket.listen(10) enough ? Should I increase it ? What is the maximum value 
for our particular server operating system ?
 
Regards,Danny SinangBusiness Process 
Reengineering
Tel: +632-855-8686  Fax: +632-855-8630www.spipublisherservices.com

CONFIDENTIALITY 
NOTICE: The contents 
of this message, and any attachments transmitted with it, are intended solely 
for the use of the addressee and may contain information that is legally 
privileged, confidential and prohibited from disclosure. If you are not the 
intended recipient, or if you are an agent responsible for delivering this 
message to the intended recipient, you are hereby notified that any 
dissemination, distribution, copying, or action taken or omitted to be taken in 
reliance on it, is unauthorized and may be unlawful. If you have received this 
message in error, please notify the sender immediately by replying to this 
message and delete the message from your computer. Please note that any views or 
opinions presented in this email are solely those of the author and do not 
necessarily represent those of the company. Finally, the recipient should check 
this email and any attachments for the presence of viruses. The company accepts 
no liability for any damage caused by any virus transmitted by this 
email.
 
<>-- 
http://mail.python.org/mailman/listinfo/python-list

python tutorial/projects

2005-02-22 Thread Danny
Does anyone know of a good python tutorial?
I was also looking for some non-trivial projects to do in python.
Basically I would like to claim on my resume, that I know python, with 
out bad karma.

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


Re: [Mingw-users] Problem with msvcrt60 vs. msvcr71 vs. strdup/free

2004-12-21 Thread Danny Smith
From: "Gerhard Haering"
>Is there any way I can force mingw to not link in msvcr for things
>like strdup?

mdkdir /mingw/lib/msvcr71
cp -f libmsvcr71.a  /mingw/lib/msvcr71/libmsvcrt.a
gcc ${OBJECTS} -L /mingw/lib/msvcr71

Or you could hand edit gcc's specs file, replacing -lmsvcrt with -lwhatever..

Patches to facilitate switching to an alternative msvcr*.dll could be submitted
to gcc.

Danny

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


Re: [Python-Help] Programming help

2004-12-06 Thread Danny Yoo


On Mon, 6 Dec 2004, Alfred Canoy wrote:

> Please help me out:(.. I've been trying to figure this out for 2 days
> now.. I don't know what to use to print all the list of numbers. I hve
> know idea how should I do this. I tried a lot of trial & error for the
> the def, dict, .list( ). have no luck.


Hi Alfred.

When you are reading numbers from the user, you should be careful to store
those numbers somewhere.  That is, you need to "collect" each new number
in some kind of container.


Take a look at:

http://www.freenetpages.co.uk/hp/alan.gauld/tutdata.htm

The "Collections" section of that page has tutorial material on how to
collect a bunch of numbers in a single container.


Good luck to you!

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