Re: help me debug my "word capitalizer" script

2012-08-22 Thread Rebelo

> Let's move to Bug #2:
> 
>  2. How do I escape the words that are already in uppercase? For example:
> 
> 
> 
> The input file has this:
> 
> NASA
> 
> 
> 
> The script changes this to:
> 
> Nasa
> 
> 
> 
> Is it possible to make this script look at a word, see if its first
> 
> character is capitalized, if capitalized then skip that word. If not
> 
> do the processing? I don't wan to use regex? Do I need it?

change: 
 words[i] = word.capitalize() 

into:
if word != word.upper() :
 words[i] = word.capitalize() 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Rebelo
Dana četvrtak, 8. studenoga 2012. 19:05:12 UTC+1, korisnik jkn napisao je:
> Hi All
> 
> i am trying to build up a set of subprocess.Ponen calls to
> 
> replicate the effect of a horribly long shell command. I'm not clear
> 
> how I can do one part of this and wonder if anyone can advise. I'm on
> 
> Linux, fairly obviously.
> 
> J^n

You should try to do it in pure python, avoiding shell altogether. 
The first step would be to actually write what it is you want to do.

To filter files you want to add to tar file check tarfile 
(http://docs.python.org/2/library/tarfile.html?highlight=tar#module-tarfile), 
specifically :
TarFile.add(name, arcname=None, recursive=True, exclude=None, filter=None)
which takes filter paramter :
"If filter is specified it must be a function that takes a TarInfo object 
argument and returns the changed TarInfo object. If it instead returns None the 
TarInfo object will be excluded from the archive."

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


Re: webapp development in pure python

2011-10-26 Thread Rebelo
Try Pylons. Use html templates which get populated with data from your database 
and then just render them. If you just want to display data, with simple forms 
for editing and adding Pylons framework is more then enough.

http://pylonsbook.com/en/1.1/
http://www.pylonsproject.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Local MAC Address

2010-04-07 Thread Rebelo

Lawrence D'Oliveiro wrote:

In message
, Booter 
wrote:



I am new to python ans was wondering if there was a way to get the mac
address from the local NIC?


What if you have more than one?



you can try with netifaces :
http://pypi.python.org/pypi/netifaces/0.3
I use them on both Windows and Linux
--
http://mail.python.org/mailman/listinfo/python-list


daemon.DaemonContext

2010-04-08 Thread Rebelo

i get : IOError: [Errno 9] Bad file descriptor
when i have logging and using daemon.DaemonContext()
i tried passing :
fh = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, 'midnight', 
encoding='utf-8')

with :
context = daemon.DaemonContext()
context.files_preserve=[fh]

but no good
what am i doing wrong?
--
http://mail.python.org/mailman/listinfo/python-list


Re: daemon.DaemonContext

2010-04-08 Thread Rebelo
when i use this :
 context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
files_preserve=[fh], signal_map = {signal.SIGTERM:
'terminate',signal.SIGHUP: 'terminate'})

i don't get error but i still can't write to log file
what am i doing wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: daemon.DaemonContext

2010-04-08 Thread Rebelo

Vinay Sajip wrote:

On Apr 8, 1:28 pm, Rebelo  wrote:

when i use this :
 context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
files_preserve=[fh], signal_map = {signal.SIGTERM:
'terminate',signal.SIGHUP: 'terminate'})

i don't get error but i still can't write to log file
what am i doing wrong?


My guess is - files_preserve needs to be passed a file handle and not
a logging handler.

Regards,

Vinay Sajip


thnx for help.
writing to a file works, but i need logging.
do you know where can i find good documnetation for python-daemon?
--
http://mail.python.org/mailman/listinfo/python-list


Re: daemon.DaemonContext

2010-04-08 Thread Rebelo

i found a crude workaround:
i wrote a function in which i start logging after deamon starts
--
http://mail.python.org/mailman/listinfo/python-list


Re: daemon.DaemonContext

2010-04-08 Thread Rebelo

Vinay Sajip wrote:

On Apr 8, 1:58 pm, Rebelo  wrote:

Vinay Sajip wrote:

On Apr 8, 1:28 pm, Rebelo  wrote:

when i use this :
 context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
files_preserve=[fh], signal_map = {signal.SIGTERM:
'terminate',signal.SIGHUP: 'terminate'})
i don't get error but i still can't write to log file
what am i doing wrong?

My guess is - files_preserve needs to be passed a file handle and not
alogginghandler.
Regards,
Vinay Sajip

thnx for help.
writing to a file works, but i needlogging.
do you know where can i find good documnetation for python-daemon?


No,

but see this post:

http://groups.google.com/group/comp.lang.python/msg/851ce78e53812ade

It may lead you to more information. The thread shows that Sean
DiZazzo got logging working with the package.

I think you just have to pass the file object used by the handler
(fh.stream) in the files_preserve array.

Regards,

Vinay Sajip

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


Re: Preserving logging streams through a daemon.DaemonContext switch

2010-04-08 Thread Rebelo

Ben Finney wrote:

Vinay Sajip  writes:


On Apr 8, 1:58 pm, Rebelo  wrote:

Vinay Sajip wrote:

My guess is - files_preserve needs to be passed a file handle and
not alogginghandler.


This is correct. As the ‘DaemonContext.__init__’ docstring says::

 |  `files_preserve`
 |  :Default: ``None``
 |  
 |  List of files that should *not* be closed when starting the

 |  daemon. If ``None``, all open file descriptors will be closed.
 |  
 |  Elements of the list are file descriptors (as returned by a file

 |  object's `fileno()` method) or Python `file` objects. Each
 |  specifies a file that is not to be closed during daemon start.


do you know where can i find good documnetation for python-daemon?


The docstrings and PEP 3143 are currently the best documentation for
‘python-daemon’; both describe the ‘files_preserve’ option as above.


http://groups.google.com/group/comp.lang.python/msg/851ce78e53812ade


As expressed in the referenced message, I would welcome someone writing
better documentation and contributing patches.


It may lead you to more information. The thread shows that Sean
DiZazzo got logging working with the package.


It's important to note (as you did, thanks Vinay) that none of the
‘logging.handlers’ are file descriptors. Nor are they file objects.

If we can get a Python ‘file’ object, we can use its ‘fileno()’ method
to get the file descriptor.

So how do we get the file object for a logging handler? The ‘logging’
module documentation doesn't mention any way to get at the stream object
for the handlers.

But looking at the source code for ‘StreamHandler’ on my system,
‘/usr/lib/python2.5/logging/__init__.py’, shows a ‘stream’ attribute
that is bound to the stream object. It's not marked private (i.e. it's
not named with a leading underscore), so one presumes it is part of the
public API.


I think you just have to pass the file object used by the handler
(fh.stream) in the files_preserve array.


Not quite. As the docs specify, you need to pass the *file descriptors*
for the files you want preserved. For regular Python file objects, the
‘file.fileno()’ method returns the file descriptor:

lh = logging.handlers.TimedRotatingFileHandler(
LOG_FILENAME,
# …
)
log_stream_descriptor = lh.stream.fileno()

daemon_context.files_preserve = [log_stream_descriptor]




thank you both for a detailed explanation.
--
http://mail.python.org/mailman/listinfo/python-list


Re: missing dll follow-up

2010-04-14 Thread Rebelo

Alex Hall wrote:

Hi again,
I said "msvcr90.dll", but I meant "msvcp90.dll". In either case, I
cannot locate the dll to include in my project and I am not sure what
else I can do. The vcredist_x86 was, I thought, supposed to give me
the dll, but it does not seem to have done so.

i think that you nedd Microsoft Visual Studio C++ for that dll file, I 
used Microsoft Visual Studio C++ Express

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


Re: msvcr90.dll is MIA?

2010-04-14 Thread Rebelo

> Alex Hall wrote:

but I still have no dll. I installed vs2005, but apparently I
need vs2008, which I cannot find.

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





http://www.microsoft.com/express/Downloads/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Linux servers, network and file names

2010-04-23 Thread Rebelo

Infinity77 wrote:

Hi All,

I apologize in advance if this sounds like a stupid question but I am
really no expert at all in network things, and I may be looking in the
wrong direction altogether.

At work we have a bunch of Linux servers, and we can connect to them
with our Windows PCs over a network. Now, let's assume we only have
one Linux server, let's call it SERVER. Everyone of us, on our Windows
PC, can map this server as a network drive choosing whatever Windows
"drive letter" he wants. For example, I could map SERVER to be "Y:/",
my colleague might call it "Z:/" and so on.

The problem arises in one of my little applications, which allows the
user to choose a file living in SERVER and do some calculations with
it; then, this file name gets saved in a common database (common in
the sense that it is shared between Windows users, ourselves). Now, I
choose this file myself, the FileDialog (a window representing a file
selector dialog) will return something like this (let's ignore the
back/forward slashes, this is not an issue):

Y:/Folder/FileName.txt

If my colleague does it, he will get:

Z:/Folder/FileName.txt

Even if I am able to work out the server name using the Windows drive
letter (and I was able to do it, now I don't remember anymore how to
do it), what I get is:

For me:  //SERVER/gavana/Folder/FileName.txt
Colleague: //SERVER/Colleague/Folder/FileName.txt

So, no matter what I do, the file name stored in the database is user-
dependent and not universal and common to all of us.

Am I missing something fundamental? I appreciate any suggestion, even
a Windows-only solution (i.e., based on PyWin32) would be perfect.

Thank you in advance for your help.

Andrea.



why don't you store servers path to file in a database?
example:
//SERVER/Public/file.txt

this way you can use python to list files in share without the need for 
mapping drives, if permissions are set correctly.


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


Re: Iterating over dict and removing some elements

2010-05-12 Thread Rebelo

On 05/11/2010 05:08 PM, Ulrich Eckhardt wrote:

Hi!

I wrote a simple loop like this:

   d = {}
   ...
   for k in d:
   if some_condition(d[k]):
   d.pop(k)

If I run this, Python complains that the dictionary size changed during
iteration. I understand that the iterator relies on the internal structure
not changing, but how would I structure this loop otherwise?

My first approach was to simply postpone removing the elements, but I was
wondering if there was a more elegant solution.

Thanks!

Uli




i am wondering why not like this:

>>> d = {1: 'one', 2: 'two', 3: 'three'}
>>> for k,v in d.items():
... if k==1:
...  del d[k]
...
>>> d
{2: 'two', 3: 'three'}
>>>

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


Re: Hashbang error

2010-06-01 Thread Rebelo

On 06/01/2010 12:56 PM, pradeepbpin wrote:

I use gVim as an editor to create python scripts on a windows machine.
To run the same script on my ubuntu machine, I added a hashbang line
to the script. Now when I run this script from command line of ubuntu,
I get a bad interpreter error, like below

/usr/bin/python^M: bad interpreter: No such file or directory

This, I understand, is due to the interpretation of newline character
at the end of the hashbang.

I have checked and found out that this does not happen if I create the
script in Ubuntu with gVim.

Now, how can I avoid this error when I create the script on a windows
machine?



check if there is an option like in Geany to select encoding and line 
endings

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


Re: scraping from bundes-telefonbuch.de with python

2010-06-19 Thread Rebelo
On 19 lip, 12:23, davidgp  wrote:
> hello, i'm new on this group, and quiet new to python!
> i'm trying to scrap some adress data from bundes-telefonbuch.de but i
> run into a problem:
> the link is like 
> this:http://www.bundes-telefonbuch.de/cgi-btbneu/chtml/chtml?WA=20
> and it is basically the same for every search query.
> thus i need to submit post data to the webserver, i try to do this
> like this:
>
> opener = urllib2.build_opener()
> opener.addheaders = [('User-Agent', 'Mozilla/5.0 (compatible;
> Konqueror/3.5; Linux) KHTML/3.5.4 (like Gecko)')]
> urllib2.install_opener(opener)
>
> data = urllib.urlencode({'F0': 'mySearchKeyword','B': 'T','F8': 'A ||
> G','W': '1','Z': '0','HA': '10','SAS_static_0_treffer_treffer': 'Suche
> starten','S': '1','translationtemplate': 'checkstrasse'})
>
> url = 'http://www.bundes-telefonbuch.de/cgi-btbneu/chtml/chtml?WA=20'
> response = urllib2.urlopen(url, data)
>
> this returns a page saying i have to reenter my search terms..
> what's going wrong here?
>
> Thanks!!

Try mechanize : http://wwwsearch.sourceforge.net/mechanize/

import mechanize
response = mechanize.urlopen("http://www.bundes-telefonbuch.de/";)
forms = mechanize.ParseResponse(response, backwards_compat=False)
form = forms[0]
form["F0"] = "query" #enter query
html =  mechanize.urlopen(form.click()).read()
f = open("tmp.html","w")
f.writelines(html)
f.close()

Or you can try to parse response but I think that their HTML is not
valid
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python scripts from DOS

2010-07-09 Thread Rebelo
On 9 srp, 11:37, Mark Carter  wrote:
> On my machine, I can go to a DOS shell, and type
>    myscript.py
> This will cause the script to be run as a python script. So that bit
> works.
>
> On another machine, on which python was set up without admin
> privileges, if I type
>    myscript.py
> it will open the "Open With" dialog box. It wont let me execute it
> with python.exe. It asks me the same question every time, too. If I
> type
>    python myscript.py
> then everything works fine.
>
> Is there a way of setting up the "other" machine so that it replicates
> the behaviour of my machine?

http://docs.python.org/release/2.6.5/using/windows.html for python
2.6.5 on windows
especially chapter 3.3.4. Executing scripts

for python 2.7 :
http://docs.python.org/using/windows.html
same chapter

for python 3.0 :
http://docs.python.org/py3k/using/windows.html#executing-scripts


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


Re: SqlAlchemy: remote connection on problem on mysql database

2010-07-09 Thread Rebelo
from SQLAlchemy docs (http://www.sqlalchemy.org/docs/
dbengine.html#database-engine-options):
"
create_engine() URL Arguments

SQLAlchemy indicates the source of an Engine strictly via RFC-1738
style URLs, combined with optional keyword arguments to specify
options for the Engine. The form of the URL is:

dialect+driver://username:passw...@host:port/database
Dialect names include the identifying name of the SQLAlchemy dialect
which include sqlite, mysql, postgresql, oracle, mssql, and firebird.
The drivername is the name of the DBAPI to be used to connect to the
database using all lowercase letters. If not specified, a “default”
DBAPI will be imported if available - this default is typically the
most widely known driver available for that backend (i.e. cx_oracle,
pysqlite/sqlite3, psycopg2, mysqldb).
"

are you sure that phpmyadmin.myhost.com is your mysql server?
or are you missing port? usually its 3306. AFAIK


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