Re: Which non SQL Database ?

2010-12-06 Thread drygal
On Dec 4, 10:42 pm, Jorge Biquez  wrote:
> Hello all.
>
> Newbie question. Sorry.
>
> As part of my process to learn python I am working on two personal
> applications. Both will do it fine with a simple structure of data
> stored in files. I now there are lot of databases around I can use
> but I would like to know yoor advice on what other options you would
> consider for the job (it is training so no pressure on performance).
> One application will run as a desktop one,under Windows, Linux,
> Macintosh, being able to update data, not much, not complex, not many
> records. The second application, running behind  web pages, will do
> the same, I mean, process simple data, updating showing data. not
> much info, not complex. As an excersice it is more than enough I
> guess and will let me learn what I need for now.
> Talking with a friend about what he will do (he use C only) he
> suggest to take a look on dBase format file since it is a stable
> format, fast and the index structure will be fine or maybe go with BD
> (Berkley) database file format (I hope I understood this one
> correctly) . Plain files it is not an option since I would like to
> have option to do rapid searches.
>
> What would do you suggest to take a look? If possible available under
> the 3 plattforms.
>
> Thanks in advance for your comments.
>
> Jorge Biquez

Pickle dictionary object perhaps?
http://docs.python.org/library/pickle.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easy function, please help.

2011-02-09 Thread drygal
On 9 Lut, 06:29, Michael Hrivnak  wrote:
> Your function only works if n is an integer.  Example:
>
> >>> num_digits(234)
> 3
> >>> num_digits(23.4)
>
> 325
>
> When doing integer division, python will throw away the remainder and
> return an int.  Using your example of n==44, 44/10 == 4 and 4/10 == 0
>
> Before each iteration of the while loop, the given expression (in this
> case just n) is evaluated as a boolean.  Your function would act the
> same if it looked like this:
>
> def num_digits(n):
>   count = 0
>   while bool(n):
>       count = count + 1
>       n = n / 10
>   return count
>
> 0 of course evaluates to False as a boolean, which is why the while loop 
> stops.
>
> Just for kicks, this function would work about as well:
>
> def num_digits(n):
>    return len(str(n))
>
> And if either of these were a real function you planned to use, you'd
> probably want to either cast n as an int ( int(n) ) or at least check
> its type:
>
> if not isinstance(n, int):
>    raise TypeError("WTF you didn't pass me an int")
>
> Michael
>
> On Wed, Feb 9, 2011 at 12:52 AM, Nanderson
>
>  wrote:
> > def num_digits(n):
> >    count = 0
> >    while n:
> >        count = count + 1
> >        n = n / 10
> >    return count
>
> > This is a function that basically says how many digits are in a
> > number. For example,
> print num_digits(44)
> > 2
> print num_digits(7654)
> > 4
>
> > This function counts the number of decimal digits in a positive
> > integer expressed in decimal format. I get this function ALMOST
> > completely. The only thing I don't understand is why it eventually
> > exits the loop, and goes off to the second branch. "while n" is
> > confusing me. What I am thinking is that if someone puts "while n" the
> > loop would be infinite. I get what is happening in the function, and I
> > understand why this would work, but for some reason it's confusing me
> > as to how it is exiting the loop after a certain number of times. Help
> > is appreciated, thanks.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>
I guess it needs:

def num_digits(n):
   return len(str(n)) -1

or

>>> x = lambda a: len(str(a).replace(".",""))
>>> x(23.5454)
6

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


Re: stupid question about html page

2010-07-01 Thread drygal
On 1 July, 09:31, luca72  wrote:
> On 1 Lug, 10:16, Mithrandir 
> wrote:
>
>
>
>
>
> > luca72  wrote in news:abfb7720-6132-4b7b-8084-
> > 5c1a48164...@y11g2000yqm.googlegroups.com:
>
> > > hello
> > > with webbrowser i open the html or php etc page, how i can save the
> > > opened page with python?
>
> > > Thanks
>
> > > Luca
>
> > Not sure of a way to capture info from a browser (like Firefox.) I know
> > though that you can save the source of an page with:
>
> > import urllib
> > urllib.urlretrieve("http://www.example.com/";, "Fun.html")
>
> > You still need a web browser to read it formatted. (If you are on a web
> > page in Firefox, and want to save it, click File>Save Page As...)
>
> > If you want to save a picture from the Net see:
>
> >http://www.daniweb.com/code/snippet216796.html
>
> > Good luck!
>
> > --
> > People should read 
> > more.https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain
> > "All that is gold does not glitter,
> > not all those who wander are lost;
> > the old that is strong does not wither,
> > deep roots are not reached by the frost.
> > From the ashes a fire shall be woken,
> > a light from the shadows shall spring;
> > renenwed shall be blade that was broken,
> > the crownless again shall be king."
>
> Thanks for your reply, the problem is that i don't want to save it
> with file-> save.
> there is any way to save the page by script.
> please note that when i save the page with firefox, it save the html
> page and also make a folder with the script used in the page, how i
> can make it also with python script?
> Thanks
>
> Luca

It is not quite possible. If python is used, it runs behind the scenes
and generates html send to the browser. You could only see the .py
file if the server was poorly configured so it would show the content
of the .py file instead of actually executing it to generate the html
code, but in that case you would not see any page either.

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