If I put any print statements at the top of my module, not inside any class/function, nothing gets printed while running my test through nose.
import os
print 'hi'
#----------------------------------------------------------------------
def make_shapes(canvas):
"""
Generates shapes. Needs a Canvas instance to add the shapes to
...
From Dive into Python:
Class attributes are available both through direct reference to the class and through any instance of the class.
Class attributes can be used as class-level constants, but they are not really constants. You can also change them.
So I type this into idle:
IDLE 2.6.5
>>> class c:
counter=0
>>> c
...
I'm trying to iterate through an Expando-Model's dynamic properties in order to output them all. Is there a way of doing this other than creating your own method like such:
class Event(db.Expando):
platform = db.ReferenceProperty(Platform)
date = db.DateTimeProperty()
def getValues(self):
return self._dynamic_proper...
After implementing some of the solutions in my previous question, I've come up with the following solution:
reader = open('C://text.txt')
writer = open('C://nona.txt', 'w')
counter = 1
names, nums = [], []
row = reader.read().split(' ')
x = len(row)/2
for (a, b) in [(c, d) for c, d in zip(row[:x], row[x:]) if d!='na']:
prin...
I am writing a simple http server as part of my project. Below is a skeleton of my script:
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class MyHanlder(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
...
I have an executable file, named, for example, resource.py. It is disposed in the folder named resource. Renaming file or folder is objectionable - it is old product and users accustomed to use such naming. At old version it was under another project, so imports to it sound like import main_product.resource.<..>.
Now I need to use impor...
Hello,
I have these classe where items (class Item) is related to channel object:
channel_items = Table(
"channel_items",
metadata,
Column("channel_id", Integer,
ForeignKey("channels.id")),
Column("item_id", Integer,
ForeignKey(Item.id))
)
class Channel(rdb.Model):
""" S...
I am writing a script to capture message off a serial port, compare them against filters and pass them to the correct place if they match the filter. The program structure is to have a serial handling thread, a message handling thread and then allow engineers to write plugins to sit on top all of this. It all works great and is fast enou...
How can I check if any of the strings in an array exists in another string?
Like:
a = ['a', 'b', 'c']
str = "a123"
if a in str:
print "some of the strings found in str"
else:
print "no strings found in str"
That code doesn't work, it's just to show what I want to achieve.
...
How do you guys go about storing your python modules locally? And how do you then go about referencing them in your python scripts?
Should I do this?
/home/python/modules
And then create a sub-directory for each module, like say the amazon s3 module:
/home/python/modules/amazon-s3/s3.py
Now I have to somehow tell python to look a...
I understand that NSIS supports plugins, but I can't find an NsPython tutorial.
Maybe first I should ask: if I can run Python code from NSIS, is it a good idea to script my installer in Python (instead of explicitly managing a stack in an NSIS script)?
And secondly: are there any good tutorials?
Alternatively: Is there another appro...
I have this weird problem as to how to name objects of a class.
For example, consider the class:
>>> class DoSomething:
pass
What should I call the object of this class? do_something or what? Since I came out of the learning stage, I used to use x, y or z or whatever came to my mind. But now since I am learning to write prop...
Hi Guys!
I'd like to stop the loading of a module if some modules dependencies arent on machine, how can i do that?
try:
import lxml
except:
print "This module requires lxml"
# WHAT SHOULD I PUT HERE TO STOP MODULE LOADING?
class foo:
pass
...
I found this interesting item in a blog today:
def abc():
try:
return True
finally:
return False
print "abc() is", abc()
Can anyone tell why it does what it does?
Thanks,
KR
...
I am a beginner and just started learning Python couple days ago (yay!)
so i've come across a problem. when i run, this code outputs everything but the text (txt in file is numbers 0-10 on seperate lines)
def output():
xf=open("data.txt", "r")
print xf
print("opened, printing now")
for line in xf:
print(xf.read(...
Does anyone know how to set a custom icon for a program in the taskbar?
I know that you can make a shortcut to a program to get whatever icon you want in the top left corner of the program (see image below for refrance) but how do I make a program get a new icon in the taskbar?
...
I monkey-patched User model with the following two lines:
User._meta.get_field_by_name('email')[0]._unique = True
User._meta.get_field_by_name('email')[0].max_length = 125
-- and noticed, that models loaded after those two lines are executed, are not reachable from User.objects.filter(). For example, I have UserProfile model, ...
I have a dictionary (index2) of 3-item lists, organized by key from 0-150 or so. I need to sort it into another dictionary, with the following constraints:
1.) all items attached to one key must stay together in the second dictionary
2.) length of items in the second dictionary must all be the same. To help with this one, I divided the t...
I have a python app in which I am creating packages in windows to be used and later compared in a linux python app. I am creating an md5 for a file in windows to be checked later in linux. The problem is that the same code on the same file gives different Md5 hash results in each environment. Below is the method I use to calculate the...
A newbie question but.....
I've installed python2.7 on a host where the system version is 2.3 (2.7 at ~/python2.7/bin/python). I'd like to add a few packages such as MySQLdb but need setuptools.
The directions say that you can use --prefix as an argument. However, if I do the following:
sh setuptools-0.6c11-py2.7.egg --prefix=~/python...