|
|
Up |
|
|
  |
Author: bsagertbsagert
Date: Jul 1, 2008 23:25
This simple script writes html color codes that can be viewed in a
browser. I used short form hex codes (fff or 000, etc) and my list
has only six hex numbers otherwise the results get rather large. I
invite criticism as to whether my code is "pythonic". Are there other
ways to generate the hex combos besides the nested "for" loops? Thanks
in advance, Bill
list = ['3','6','9','b','d','f']
s = '\n'
for a in list:
for b in list:
for c in list:
s += ' '+ a + b + c +'
\n'
s += ''
f = open('c:/x/test.htm', 'w')
f.write(s)
f.close()
|
| |
|
| |
3 Comments |
|
  |
|
|
  |
Author: shandy.bshandy.b
Date: Jul 1, 2008 22:43
I'm trying to write some code to deal with world timezones, and I'm
getting a strange result. America/Iqaluit should not be showing up in
UTC+00:00, but it is. Can anyone see what's wrong with this code?
import time
from datetime import datetime
import os
import pytz
def getZoneNamesOnThisComputer():
for i in pytz.all_timezones:
if os.path.exists( os.path.join('/tmp/usr/share/zoneinfo/',
i)):
yield i
|
| Show full article (1.30Kb) |
|
3 Comments |
|
  |
Author: Guilherme PoloGuilherme Polo
Date: Jul 1, 2008 18:14
On Tue, Jul 1, 2008 at 9:51 PM, Joe Goldthwaite goldthwaites.com> wrote:
> I'm confused. (Not a new experience). I've got a web application running
> under Zope. I use the Wing IDE for testing and debugging. When trying to
> recreate problems that come up on the web, I wrote some little routines that
> pull my cookies out of the Firefox cookies.txt file into my code. That way,
> I'm working with all the same options under Wing that my app uses when
> running under Zope.
>
> That's worked great until I upgraded to Firefox 3. Firefox 3 moved their
> cookies from cookies.txt to cookies.sqlite. I haven't worked with SQLite at
> all so I started searching for examples and found this;
>
> import sqlite3
> conn = sqlite3.connect('test.db')
> c = conn.cursor()
> rows = c.execute('SELECT * from somefile')
>
> Looks simple enough but I can't get it to work. Here are my questions;
>
> 1. How do you get sqlite3 for Python 2.4? I can't find it anywhere. ...
|
| Show full article (2.32Kb) |
|
no comments
|
|
  |
Author: Joe GoldthwaiteJoe Goldthwaite
Date: Jul 1, 2008 17:51
I'm confused. (Not a new experience). I've got a web application running
under Zope. I use the Wing IDE for testing and debugging. When trying to
recreate problems that come up on the web, I wrote some little routines that
pull my cookies out of the Firefox cookies.txt file into my code. That way,
I'm working with all the same options under Wing that my app uses when
running under Zope.
That's worked great until I upgraded to Firefox 3. Firefox 3 moved their
cookies from cookies.txt to cookies.sqlite. I haven't worked with SQLite at
all so I started searching for examples and found this;
import sqlite3
conn = sqlite3.connect('test.db')
c = conn.cursor()
rows = c.execute('SELECT * from somefile')
Looks simple enough but I can't get it to work. Here are my questions;
1. How do you get sqlite3 for Python 2.4? I can't find it anywhere.
2. If sqlite3 is only for Python 2.5, does sqlite2 work the same way?
3. Looking at the cookies.sqlite file, I see some text right at the top
"SQLite format 3". Does that mean that I need to use sqlite3?
|
| Show full article (1.72Kb) |
|
2 Comments |
|
  |
Author: BrandonBrandon
Date: Jul 1, 2008 15:20
What I'm trying to do is essentially force a user to fill in required items
in a form, which will be saved to a database. How can I get it so that once
the user clicks "OK" on the dialog box, it transfers control back to the
form, and not save the empty fields into the database?
|
| |
|
2 Comments |
|
  |
Author: PlayDoughPlayDough
Date: Jul 1, 2008 14:49
I've embedded Python in an extension for a program we are using here
at work. And I'm a bit stumped as to why I am getting an
AttributeError only in the embedded Python.
First, a bit of what I am doing. We use a simulator for a
microprocessor we are using in our systems. Our simulator allows for
extensions that can be loaded as shared libraries. Rather than code
the entire extension in C/C++, I would like to make use of Python to
script the extension.
So, I first initialize Python (examples below leave out the error
checking, but it is there):
Py_Initialize();
And then I make sure the script directory is in the path with
Py_GetPath() and PySys_SetPath().
Finally, I import the script (say it is in a local file 'script.py'):
pName = PyString_FromString("script");
pModule = PyImport_Import(pName);
Once the module is imported, I get objects to the functions in the
script I want to call later, which I do with:
|
| Show full article (2.12Kb) |
|
no comments
|
|
  |
Author: chamaluluchamalulu
Date: Jul 1, 2008 14:20
Hello.
I think I'm aware of how attribute access is resolved in python. When
referencing a class instance attribute which is not defined in the
scope of the instance, Python looks for a class attribute with the
same name. (For assignment or deletion this is not the case,
thankfully.)
I've been trying to understand why? What is the reason behind, or
practical purpose of, this design decision? Anyone, please enlighten
me.
/Henrik
|
| |
|
8 Comments |
|
  |
Author: Kurda YonKurda Yon
Date: Jul 1, 2008 13:43
Hi,
I have a class called "vector". And I would like to define a function
"dot" which would return a dot product of any two "vectors". I want
to call this function as follow: dot(x,y).
Well, I can define a functions "dot" outside the class and it works
exactly as I want. However, the problem is that this function is not
associated with the class (like methods a method of the class).
For example, if I call "x.calc()" or "y.calc()", python will execute
different methods if "x" and "y" belongs to different classes. I want
to have the same with my "dot" function. I.e. I want it calculates the
dot product ONLY IF the both arguments of that function belong to the
"vector" class.
Is it possible?
Thank you in advance.
|
| |
|
7 Comments |
|
  |
|
|
  |
Author: Terry ReedyTerry Reedy
Date: Jul 1, 2008 12:46
Peter Bulychev wrote:
> Hello.
>
> I want to convert unicode character into ascii one.
> The method ".encode('ASCII') " can convert only those unicode
> characters, which fit into 0..128 range.
>
> But there are still lots of characters beyond this range, which can be
> manually converted to some visibly similar ascii characters. For
> instance, there are several quotation marks in unicode, which can be
> converted into ascii quotation mark.
>
> Can this conversion be performed in automatic manner? After googling
> I've only found that there exists Unicode database, which stores
> human-readable information on notation of all unicode characters
> ( ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt). And there also
> exists the Python adapter for this database
> ( http://docs.python.org/lib/module-unicodedata.html). Using this
> database I can do something like `if
> notation.find('QUOTATION')!=-1:\n\treturn "'"`. I believe there is more ...
|
| Show full article (1.17Kb) |
|
no comments
|
|
|
|
|
|
|