How to run a setup command with 'pip install'?

2011-08-25 Thread Andrei
Hello,

I have a trouble installing the DMSL package with pip. The package doesn't have 
*.c files, which must be produced with Cython by 'pyhton setup.py build_ext' 
command. How do I run it with 'pip install'?

Please see http://stackoverflow.com/questions/7189336/ for details.

Regards,
Andrei
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a setup command with 'pip install'?

2011-08-25 Thread Andrei
'pip install pyrex' solved the problem (credit to @jezdez)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semicolons

2005-04-11 Thread Andrei
Mage  mage.hu> writes:

> I amafraid of I will stop using semicolons in other languages after one
> or two months of python. However I see that python simply ignores the
> semicolons atd the end of the lines.

I notice that when switching between Python and Delphi I'll sometimes type "if
... then ..." constructs in Python or "if ... :" in Delphi, or define classes
the wrong way, but I get used to the different syntax extremely quickly (I might
make a mistake once or twice, that's it). Same goes for semicolons. 

So I wouldn't worry about it, just write Python in Python, PHP in PHP, C in C,
etc. The semicolons are only a very small part of the differences between
languages and their absence is detected by the compiler when you forget them.

Yours,

Andrei




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


Detect if specific Python.app instance is already running

2015-06-07 Thread Andrei
Hello,

I am experimenting with OS X apps written in Python and need to detect if there 
is already an instance of Python.app running with certain script. My script 
modifies CFBundleName on-the-fly from "Python" to "MyApp" to change the app 
title in the menubar. If I start another instance and check CFBundleName of the 
running apps, it will only tell me the original value, i.e. "Python":

for app in NSWorkspace.sharedWorkspace().runningApplications():
bundle = NSBundle.bundleWithURL_(app.bundleURL())
name = bundle.infoDictionary().get('CFBundleName')
if name in ('Python', 'MyApp'):
print name  # => prints Python

So I need to find a way to mark a Python.app instance that runs MyApp script to 
be able to abort launching duplicate instances. Is there such way?

Thanks,
Andrei
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Detect if specific Python.app instance is already running

2015-06-07 Thread Andrei
Alright, I have had some development in 
http://stackoverflow.com/questions/30694560/detect-if-specific-python-app-instance-is-already-running
 and can prevent running multiple instances of the same app/script (by lockf), 
but I still need to identify which Python.app instance is running certain 
script. I guess it's more Cocoa-related question but I hope someone had same 
problem with tkinter etc.

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


Re: Detect if specific Python.app instance is already running

2015-06-08 Thread Andrei
On Monday, June 8, 2015 at 1:08:07 AM UTC+2, Ned Deily wrote:
> In article <[email protected]>,
>  Andrei wrote:
> > Alright, I have had some development in 
> > http://stackoverflow.com/questions/30694560/detect-if-specific-python-app-inst
> > ance-is-already-running and can prevent running multiple instances of the 
> > same app/script (by lockf), but I still need to identify which Python.app 
> > instance is running certain script. I guess it's more Cocoa-related 
> > question 
> > but I hope someone had same problem with tkinter etc.
> 
> Can you give a more complete explanation of the goal, i.e. what you are 
> trying to end up with here, rather than the steps you are taking to get 
> there?  It's not at all clear to me what your goal is and the cumbersome 
> steps you find you have to take suggest that you might be going down the 
> wrong path.  OS X apps usually don't have to resort to such hacks.  If 
> you haven't already, make sure you have looked at the "Information 
> Property List Key Reference" for OS X (and iOS) apps.  For instance, key 
> LSMultipleInstancesProhibited *might* be useful if you really only want 
> to ensure that there is only instance of an app launched.
> 
> https://developer.apple.com/library/mac/documentation/General/Reference/I
> nfoPlistKeyReference/Articles/LaunchServicesKeys.html
> 
> -- 
>  Ned Deily


Hi Ned,
Thanks for your reply! The problem is a bit tricky as I see it. Multiple 
instances of Python.app needs to be run since it may run different tkinter apps 
etc. What I need is rather simple:

1. start app, mark the instance with tkinter app name
2. start another one, detect that the same instance is already running and 
identify it
3. focus on the first instance, close the second one

I have solved it with a lock file and a pid file (I guess I could use just one 
file for both jobs, but didn't have time to test it yet). I believe it could be 
done without files, i.e. by setting some public attributes on app instances. I 
could probably also use OS X key storage for this but it gets too similar to 
the file approach and I am not sure if it's any better.

I may be wrong in my thinking. If so, just let me know :)

Thanks,
Andrei
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Looking for a python IDE

2006-09-16 Thread Andrei
> I am looking for a good IDE for Python. Commercial or Open Software.
> If possible with visual GUI designer.
 > For the moment I am considering Komodo.

There is no Python IDE that has a fully-integraded approach like Delphi 
or VS with all bells and whistles. Tools tend to be somewhat separate 
and can be combined at will, using any editor you like with any GUI 
designer you like. Boa constructor is an attempt at buildings something 
like Delphi, but it's quirky and has an unclear maintenance status.

Some of the big names in Python IDEs are Spe, Eric, Idle, PythonWin and 
WingIDE. GUI designers you can use are wxGlade (for wxPython), Glade 
(for PyGTK) and QtDesigner (for Qt). Spe + wxGlade and Eric + QtDesigner 
are natural fits.

It's really a jungle out there - your personal taste and toolkit 
preferences will have to determine your choice. If I like wxGlade, it 
won't help you if you want to build Qt apps, Eric doesn't work if you 
run Windows, etc.

Yours,

Andrei

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


Python 2.7 importing pyc files without py files

2014-02-19 Thread Mircescu Andrei
Hi,


I encountered a strange issue. I have an application which uses extensively 
python 2.7.6 (CPython).


The issue that I see is the following:
If there are only pyc files, the loading time of the application is much more 
than if I have pyc and py files. It is behind with 2 minutes more than if it 
had py files

Do you have any idea why this is happening ? Maybe is because, python tries to 
search the py file in all the paths and this search is exhaustive ? This is the 
best guess I could figure it out but I'm not sure. 

Also, if this is the scenario, there is a way I can stop this, to not search 
for the py files ? is there an api ? or a compiling flag I should set ?



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


Re: Python 2.7 importing pyc files without py files

2014-02-20 Thread Mircescu Andrei
joi, 20 februarie 2014, 00:25:41 UTC+2, Emile van Sebille a scris:
> On 2/19/2014 2:03 PM, Mircescu Andrei wrote:
> 
> 
> 
>  > If there are only pyc files, the loading time of the application is
> 
>  > much more than if I have pyc and py files. It is behind with 2
> 
>  > minutes more than if it had py files
> 
> 
> 
> You may get some clues by starting python as
> 
> 
> 
> /path/to/python/python2.7 -vv
> 
> 
> 
> which will provide the details of attempts to import:
> 
> 
> 
> [root@vsds4 log]# python2.7 -vv
> 
> # installing zipimport hook
> 
> import zipimport # builtin
> 
> # installed zipimport hook
> 
> # trying /usr/local/lib/python2.7/site.so
> 
> # trying /usr/local/lib/python2.7/sitemodule.so
> 
> # trying /usr/local/lib/python2.7/site.py
> 
> # /usr/local/lib/python2.7/site.pyc matches /usr/local/lib/python2.7/site.py
> 
> import site # precompiled from /usr/local/lib/python2.7/site.pyc
> 
> # trying /usr/local/lib/python2.7/os.so
> 
> # trying /usr/local/lib/python2.7/osmodule.so
> 
> # trying /usr/local/lib/python2.7/os.py
> 
> # /usr/local/lib/python2.7/os.pyc matches /usr/local/lib/python2.7/os.py
> 
> import os # precompiled from /usr/local/lib/python2.7/os.pyc
> 
> ...
> 
> 
> 
> 
> 
> 
> 
> HTH,
> 
> 
> 
> Emile

I cannot start python since i'm embedding it in .net with pythonnet solution.




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


Re: Remove comma from tuples in python.

2014-02-20 Thread Mircescu Andrei
vineri, 21 februarie 2014, 08:49:01 UTC+2, Jaydeep Patil a scris:
> I am getting below tuple from excel.
> 
> How should i remove extra commas in each tuple to make it easy for operations.
> 
> 
> 
> tuples is:
> 
> seriesxlist1 = ((0.0), (0.01), (0.02), (0.03), (0.04), (0.05), (0.06), 
> (0.07), (0.08), (0.09), (0.1), (0.11))
> 
> 
> 
> 
> 
> 
> 
> please suggest me solution.
> 
> 
> 
> 
> 
> 
> 
> Regards
> 
> jay

i think you have a tuple of tuples there. a tuple of 12 tuples.

you need to parse each one and represent it as you wish
-- 
https://mail.python.org/mailman/listinfo/python-list


Which Python Framework for REST API and Facebook Wrapper?

2013-09-28 Thread harry . andrei
I will be designing a REST based API for a cross-platform back end that will 
serve both desktop Facebook users as well as mobile users. It will handle 
operations such as user creation, retrieval of user and other data, payment 
verification and in the case of the desktop side, handle the html/css template 
customization. The database back end is MySQL and I do need a cache system.

Currently we were using Codeigniter (PHP) for our codebase but as CI seems on 
the way out, I do not wish to start a new project based on it. I was looking at 
Laravel for PHP, but, Python is very attractive to me as a language and since 
the introduction of WSGI, I am confident it can make a difference in 
performance and code maintainability over PHP while being able to plug in to 
our dedicated server infrastructure. 

Since I am not experienced with Python frameworks (though learning curve is not 
much of an issue for me) I look to the community to understand which Python 
framework can rival or surpass Codeigniter in terms of performance in heavy 
traffic backend solutions (over 1M requests per day, with up to 100 req/sec at 
peak). I really want to make the switch from PHP to Python as I believe that 
Python can solve more problems with less code and faster execution time, not to 
mention freedom from brackets and semicolons.
-- 
https://mail.python.org/mailman/listinfo/python-list


Get EXE (made with py2exe) path directory name

2006-06-05 Thread Andrei B
I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing
else.

I turn my script into an executable with py2exe, then I create a
shortcut to the EXE on the desktop. I change the "Start In" variable of
the shortcut "C:\somthing_else", so now the currect working directory
of the executable is not the same as the directory where the EXE is
located.

I need to load a file that's in the same directory as the EXE, so I do
the following:

dir = os.path.dirname(sys.argv[0])
filepath = os.path.join(dir, 'server.pkey')

however it doesn't seem to work.

Any idea?

thanks!

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


Information manager/organizer with tags question.

2007-11-11 Thread andrei . avk
Hello,

I would like to write an information manager/organizer type of app but
first I'd like to ask if there is something like that already
existing. I asked on yahoo questions but did not get a response. I
also searched freshmeat but even though they have plenty of projects
that are tangentially related, I was unable to find anything close
enough.

What I'm thinking about is this: a database with an interface that
stores records by tags and allows filtering and sorting by these tags.
When I enter a new record, I enter a title and any number of tags.
Interface would have a filter by: pull down menu separated in two
sections, favorite tags and recent tags. To the right of that would be
a button to add another filter, which would create a new pull down
menu to filter current results further. Then there would be a search
field where you'd type in a word and it would show a list of all
matching tags;  then you would click on one of the tags to add it to
last filter menu's 'recent' list. Interface would be two-pane with an
option to switch to single pane, where one pane is a list of matching
records and the other is current record.

List of matching records would be sortable by clicking on column
titles.

Going into the record would bring up a screen with title and body text
of the record, if the record is a file it'd show title, list of tags
and a button that opens that file. (unless it's a text file that can
be viewed and edited there).

The idea is to have a central hub of all information, that is very
easy to search and locate not only the exact document you're looking
for but also a specific subset of documents, including all of the ones
you do need and excluding ones that you do not, which allows you to
work with them as a set without the need to specifically select each
and every one you need.

For the first version it'd be enough to have plain text body field.
Later I'd like to have a rich document format, probably html.

Later I'd also like to add an option for matching synonymous words to
tags. If you search for certainty, it would match assurance tag if the
option is on.

For instance, if I wanted to find this message, I'd search for Usenet
posts, tag, my name (as author). I would know that I only made one
Usenet post about tags. If I made unrelated posts about html tags, for
instance, I'd filter by 'information manager', and then I'd find this
post and more posts that I might make about this. If I wanted to
include possible replies, I'd remove my name from filters. Then I
could sort by date to see latest posts.

The reason for this idea is that right now I keep my information, or
at least most of it, in an outliner program called treepad. It's a
tree-like view program where you make a hierarchical structure similar
to file system, where each 'file' is a text entry field. This is
reasonably useful but is limited to only one possible subset, i.e. you
could put all posts under 'Usenet posts/info manager/a, b, c' but it's
impossible to filter it further or to combine it with some subset of a
different topic. Many chunks of information belong to multiple topics
and you can't always remember if you filed under one or the other.
Therefore I think this tag-based approach would be much more flexible.

I have experience with doing a few simple apps in Tkinter and also a
db driven site in TurboGears. I'm not sure what framework I should use
for this. I generally would prefer gtk because of responsiveness and
nice looks, but it may be a bit tough since I never did any gtk
development at all. Should I prototype in Tkinter? Would Django be
better suited for this or TurboGears?

Of course there isn't any need to do anything if there is already an
app that does this. Please tell me if it does, or if there is
something very close that could have this set of features added
easily. I was thinking about wikis, in fact. I might be best off
starting with a wiki done in TurboGears and going from there. I'd get
html markup pages right away, with links, nice formatting.. TG has
many components that could be useful for this app.

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


Re: Information manager/organizer with tags question.

2007-11-12 Thread andrei . avk
On Nov 12, 2:24 pm, Aaron Watters <[EMAIL PROTECTED]> wrote:
> On Nov 11, 5:44 pm, [EMAIL PROTECTED] wrote:
>
> > Hello,
>
> > I would like to write an information manager/organizer type of app but
> > first I'd like to ask if there is something like that already...
>
> Your outline sounds like a killer app, and I don't know of anything
> like
> it (especially for free).  However, I have to plug nucular as a
> possible
> back end data store that may make it easier for you to implement the
> app you outlined.  Please have a look:
>
>  http://nucular.sourceforge.net
>
> See the "demos" for examples of what you can do with it very easily.
>-- Aaron Watters
>
> ===http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=unsuspecting+v...

Sounds interesting and thanks for reply but I need something that will
work in windows also.. -andrei

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


Re: Information manager/organizer with tags question.

2007-11-13 Thread andrei . avk
On Nov 13, 12:42 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello,
>
> > [snip outline of an information editor]
>
> Maybe the Literary Machine?
> http://sommestad.com/lm.htm>
>
> It is a bit weird at first, and Windows only (altough I have had it
> running under wine once). But it is actually really well designed and
> very powerful.

I installed it and looked at flash demos, however, I have a couple of
questions.. is there a way to filter by several keywords? Is there a
way to sort by keywords? Is there a way to add a new keyword to a
topic
that isn't in the list of keywords?



>
> Or, if it ever comes out (I've been waiting for it for YEARS now),
> perhaps Ceryle would fit the bill:
>
> http://www.altheim.com/ceryle/wiki/>

This is also interesting.. the biggest two issues for my purposes is
that it doesn't have a UI geared for the usage I was thinking of. I
was thinking of something along the lines of Treepad, which is an
incredible program because it makes operations so easy and quick to
do. ceryle seems like emacs to treepad's (and my intended program's)
vim. It just occured to me that I might want to try to hack vim into
doing this.. I'll have to think about that. It's also a little
alarming
that they didn't get it out in years. This is a very bad sign. It
looks
bloated imho.

My idea is that several key actions should be incredibly easy to do,
i.e.:
1. add keyword - already a field on screen, just click and type
2. add existing keyword out of favorites list - click a toolbar button
3. sort by keyword - popup already on screen
4. filtering by two / three keywords is the most common usage scenario
and
therefore should be possible in 3 clicks - one for each keyword.

Otherwise, if these actions are buried somewhere, you will simply not
use
them often enough to make the whole thing consistently searchable by
the
tags. You will think "oh wait I can search for that tag and that other
one"
and then you will think "did I add keywords to that item?".

I'd like to try to make it possible to have tags as an integral and
inherent
part of each and every doc. Otherwise they'll end up like webpage tags
-
a bit of help with adding weight to full search.

I don't mean to criticize these programs, they're very interesting and
I'm
glad you brought them to my attention. I'm not sure I understood the
first
one properly, it may be that it is possible to do what I'm thinking of
in it,
I just didn't spot that in the interface. Please help if that is the
case!

However they seem to have different focus and that's important because
both
are closed, at least now, so it's not the case I was thinking of of
some
light simple wiki system where I'd have to add a few features.

Again, thanks for your response! -andrei

>
> There once was some code to download, but I couldnt get it to compile.
> The guy who writes the software is a really approachable, nice guy.
> Maybe if you contact him and politely prod him into finally getting the
> thing out, nobody will ever need to write any information manager anymore.
>
> /W


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


Re: Information manager/organizer with tags question.

2007-11-13 Thread andrei . avk
On Nov 13, 12:42 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello,
>
> > [snip outline of an information editor]
>
> Maybe the Literary Machine?
> http://sommestad.com/lm.htm>
>
> It is a bit weird at first, and Windows only (altough I have had it
> running under wine once). But it is actually really well designed and
> very powerful.

I installed it and looked at flash demos, however, I have a couple of
questions.. is there a way to filter by several keywords? Is there a
way to sort by keywords? Is there a way to add a new keyword to a
topic
that isn't in the list of keywords?



>
> Or, if it ever comes out (I've been waiting for it for YEARS now),
> perhaps Ceryle would fit the bill:
>
> http://www.altheim.com/ceryle/wiki/>

This is also interesting.. the biggest two issues for my purposes is
that it doesn't have a UI geared for the usage I was thinking of. I
was thinking of something along the lines of Treepad, which is an
incredible program because it makes operations so easy and quick to
do. ceryle seems like emacs to treepad's (and my intended program's)
vim. It just occured to me that I might want to try to hack vim into
doing this.. I'll have to think about that. It's also a little
alarming
that they didn't get it out in years. This is a very bad sign. It
looks
bloated imho.

My idea is that several key actions should be incredibly easy to do,
i.e.:
1. add keyword - already a field on screen, just click and type
2. add existing keyword out of favorites list - click a toolbar button
3. sort by keyword - popup already on screen
4. filtering by two / three keywords is the most common usage scenario
and
therefore should be possible in 3 clicks - one for each keyword.

Otherwise, if these actions are buried somewhere, you will simply not
use
them often enough to make the whole thing consistently searchable by
the
tags. You will think "oh wait I can search for that tag and that other
one"
and then you will think "did I add keywords to that item?".

I'd like to try to make it possible to have tags as an integral and
inherent
part of each and every doc. Otherwise they'll end up like webpage tags
-
a bit of help with adding weight to full search.

I don't mean to criticize these programs, they're very interesting and
I'm
glad you brought them to my attention. I'm not sure I understood the
first
one properly, it may be that it is possible to do what I'm thinking of
in it,
I just didn't spot that in the interface. Please help if that is the
case!

However they seem to have different focus and that's important because
both
are closed, at least now, so it's not the case I was thinking of of
some
light simple wiki system where I'd have to add a few features.

Again, thanks for your response! -andrei

>
> There once was some code to download, but I couldnt get it to compile.
> The guy who writes the software is a really approachable, nice guy.
> Maybe if you contact him and politely prod him into finally getting the
> thing out, nobody will ever need to write any information manager anymore.
>
> /W


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


Open a file with default handler app?

2008-03-11 Thread andrei . avk
Hi, I searched for this on google and in this group, but my awesome
google-fu powers failed me. Is there a way to open any file using
default program that'd open it? In other words, to do the same action
as double-clicking in windows explorer? And secondly, is there a way
to do the same thing for linux that'd work across all desktop
environments and distributions, or at least in all major ones? What
I'm trying to do here is to have records (or items) in my app where
you could attach any kind of file and open it from there by clicking
'open'. Then it would go and do something like os.system("launch %s" %
filename). So any way to do this except for keeping your own
dictionary of file types and relevant apps? thx, -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open a file with default handler app?

2008-03-12 Thread andrei . avk
On Mar 11, 11:50 pm, [EMAIL PROTECTED] wrote:

>
> Hey there,
> I've had to do the same things for a program that I'm writing. The
> following command should do the trick:
>
> os.startfile("yourfilehere")
>
> from the os module. Hope this helps!

That's perfect, thanks a ton++!
-- 
http://mail.python.org/mailman/listinfo/python-list


escape string to store in a database?

2008-03-12 Thread andrei . avk
Hi, I'd like to store chunks of text, some of them may be very large,
in a database, and have them searchable using 'LIKE %something%'
construct. These pieces of text may have single and double quotes in
them, I tried escaping them using re module and string module and
either I did something wrong, or they escape either single quotes or
double quotes, not both of these. So that when I insert that text into
a db record, this causes an error from the database. What's the
accepted way of dealing with this? I have a workaround currently where
I encode the string with b64, and then unencode it when searching for
a string, but that's a dumb way to do this. For my app, searching
quickly is not very crucial, but would be nice to have.. thanks, -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a Roguelike in Python

2008-03-12 Thread andrei . avk
On Mar 12, 8:25 am, [EMAIL PROTECTED] wrote:
> Seeing the 7DRL start up recently, i wanted to see what one was made
> of. Python is the language i'm most familiar with so i searched for
> some code to look at, but i couldn't find any. Can anyone direct me to
> the right place?
>
> I did some searching on what it would take to write a roguelike in
> python and it looked like the curses module would work perfectly, but
> it looks to me like it doesn't work in windows? I tried to import it
> and it says 'No Module named _curses'
>
> Sorry if all this sounds a bit noobish, it's only cause i am.

I made a very small basic roguelike, except that in it you control
the monsters instead of the hero. It uses curses so no worky in
windows.
Here:

http://silmarill.org/nodes/I,_monster_game.html

I later modified this game to control the hero and sometimes to ask
you multiple-choice questions from biology and other fields of
knowledge,
and based on your right/wrong answer it either makes a Hit for your HP
or gives you a small reward. If there's interest i can post that
updated
game too. Both are kind of buggy though.. -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escape string to store in a database?

2008-03-13 Thread andrei . avk
 On Mar 12, 8:32 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-03-12 at 18:18 -0700, [EMAIL PROTECTED] wrote:
> > These pieces of text may have single and double quotes in
> > them, I tried escaping them using re module and string module and
> > either I did something wrong, or they escape either single quotes or
> > double quotes, not both of these. So that when I insert that text into
> > a db record, this causes an error from the database. What's the
> > accepted way of dealing with this?
>
> The accepted way of dealing with this is to use parameter binding:
>
> conn = somedbmodule.connect(...)
> cur = conn.cursor()
> cur.execute("insert into sometable(textcolumn) values (?)",
>             (stringvar,) )
>
> (Note that the question mark may have to be replaced with %s depending
> on which database module you're using.)
>
> For background information on parameter binding see, for 
> example,http://informixdb.blogspot.com/2007/07/filling-in-blanks.html.
>
> HTH,
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

Thanks for the reply, Carsten, how would this work with UPDATE
command? I get this error:

cmd = "UPDATE items SET content = ? WHERE id=%d" % id

self.cursor.execute(cmd, content)
pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings
supplied. The c
rrent statement uses 1, and there are 0 supplied.

Sqlite site doesn't give any details on using parameter bindings in
UPDATE command, I'm
going to look around some more.. -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escape string to store in a database?

2008-03-14 Thread andrei . avk
On Mar 14, 1:36 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Thu, 13 Mar 2008 19:55:27 -0700 (PDT), [EMAIL PROTECTED] declaimed
> the following in comp.lang.python:
>
>
>
> > Thanks for the reply, Carsten, how would this work with UPDATE
> > command? I get this error:
>
> >         cmd = "UPDATE items SET content = ? WHERE id=%d" % id
>
>                 cmd = "update items set content = ? where id = ?"
>
> >     self.cursor.execute(cmd, content)
>
>                 self.cursor.execute(cmd, (content, id))
>
> would be the preferred method...

Thanks very much - this works perfectly -ak

>
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [EMAIL PROTECTED]               [EMAIL PROTECTED]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [EMAIL PROTECTED])
>                 HTTP://www.bestiaria.com/

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


Re: replace string in a file

2008-03-15 Thread andrei . avk
On Mar 15, 3:54 pm, Unknown <[EMAIL PROTECTED]> wrote:
> Hi,
> I've got this code :
>
> cb = open("testfile", "r+")
> f = cb.readlines()
> for line in f:
>     rx = re.match(r'^\s*(\d+).*', line)
>     if not rx:
>         continue
>     else:
>         serial = rx.group(1)
>         now = time.time()
>         today = time.strftime('%Y%m%d00', time.localtime(now))
>         todayVal, serialVal = long(today), long(serial)
>         if todayVal <= serialVal:
>             todayVal = serialVal + 1
>         else:
>             todayVal += 1
>         line = string.replace(line, serial, "%d" %todayVal)
>         cb.write(line + "\n")
>         print 'Updated serial from "%s" to "%d"' % ( serial, todayVal )
>         break      
> cb.close()
>
> I was expecting to replace the old value (serial) with the new one
> (todayVal). Instead, this code *adds* another line below the one found...
>
> How can I just replace it?
>
> Thanks for your help :-)

What you want to do is either 1. load everything up into a string,
replace
text, close file, reopen it with 'w' flag, write string to it. OR if
file is too big, you can read each line, replace, write to a temp
file,
then when done move the file over the old one.

I think there are technical reasons why file-reading and iteration api
are not very suitable for reading and writing at the same time. I
think
you'd have to set the filepointer back one line (it can be manipulated
by giving it bytes ahead/back, so that would be difficult in itself),
then delete the line and then write new string. It may be even harder
than
that, I'm sure someone can explain this much better, but you're far
better
off with using one of the 2 methods above.. HTH, -ak
-- 
http://mail.python.org/mailman/listinfo/python-list