the next is my code:
class foo:
def __init__(self):
self.a = "a"
def __getattr__(self,x,defalut):
if x in self:
return x
else:return defalut
a=foo()
print getattr(a,'b','sss')
i know the __getattr__ must be 2 argument,but i want to get a default attribute if the attribute is no being.
h...
I'm still learning so please forgive if this sounds like a dumb question. Is it possible to define input times, like time, date, currency or that should be verified manually? Like for example:
morning = input('Enter morning Time:')
evening = input('Enter evening Time:')
.. I need (only) time here, how do I make sure that user enters i...
Source text: United States Declaration of Independence
How can one split the above source text into a number of sub-strings, containing an 'n' number of words?
I use split(' ') to extract each word, however I do not know how to do this with multiple words in one operation.
I could run through the list of words that I have, and create...
When I do json.dumps with a dictionary that maps strings to a list of unicodes, python raises a type error. Why does that not work?
...
This script won't compile. I wanted to made a simple 21-style game for practice but I get an error:
X@X:~/Desktop$ python 21.py File "21.py",
line 18
int(ptotal) = ptotal + newcard
SyntaxError: can't assign to function call
Here's the code. Can anyone please help me? I'm obviously a beginner and the code is pretty sloppy.
...
Hi alls,
I would like to encode "ITSATEST" to it's netbios name value in python;
The occurence table and explication are here:
http://support.microsoft.com/kb/194203
I dont know how this could be done easily in python, someone can give me a hand ?
Thanks !
...
Does anyone know if I can call epoll.register from another thread safely?
Here is what I am imagining:
Thread 1: epoll.poll()
Thread 2: adding some fd to the same epoll object with epoll.register
http://docs.python.org/library/select.html
...
i used python 2.5,i want to know how can change the next code when the Platform is python2.5 or python2.6
class C(object):
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.delete...
Is there a way in windows by which I can toggle the audio output between a built-in speaker and the headphone jack using a python library.
I am thinking someone with .NET experience would be able to give me some pointers (I could use IronPython if there is a .NET library to do that).
I have no idea where to start. Any hints would help....
enter time-1 // eg 01:12
enter time-2 // eg 18:59
calculate: time-1 to time-2 / 12
// i.e time between 01:12 to 18:59 divided by 12
How can it be done in Python. I'm a beginner so I really have no clue where to start.
Edited to add: I don't want a timer. Both time-1 and time-2 are entered by the user manually.
Thanks in advance fo...
I'm creating a python script which accepts a path to a remote file and an n number of threads. The file's size will be divided by the number of threads, when each thread completes I want them to append the fetch data to a local file.
How do I manage it so that the order in which the threads where generated will append to the local file ...
I am creating a site similar to reddit and hacker news that has a database of links and votes. I am implementing hacker news' popularity algorithm and things are going pretty swimmingly until it comes to actually gathering up these links and displaying them. The algorithm is simple:
Y Combinator's Hacker News:
Popularity = (p - 1) / ...
I'm converting a single module using 2to3.
test_lib2to3.py is in /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/test/test_lib2to3.py
File to be converted is in /Users/Nimbuz/Documents/python31/Excercise 1/time3.py
Terminal Session:
localhost:test Nimbuz$ 2to3 /Users/Nimbuz/Documents/python31/Excercise\ 1/time3.py
Ref...
I use the following two methods to to generate text preview image for a .ttf font file
PIL method:
def make_preview(text, fontfile, imagefile, fontsize=30):
try:
font = ImageFont.truetype(fontfile, fontsize)
text_width, text_height = font.getsize(text)
img = Image.new('RGBA', (text_width, text_height))
...
What would you suggest what will be the next choice of language that could benefit an engineer in his career utmost? I am a Software Engineer and almost everything I engineered is for WWW.
I have decided to learn a language and keep it learning parallel. I'm fluent in C# and JavaScript. But, apart from it I want to learn a language whic...
Source:
[This] is some text with [some [blocks that are nested [in a [variety] of ways]]]
Resultant text:
[This] is some text with
I don't think you can do a regex for this, from looking at the threads at stack overflow.
Is there a simple way to to do this -> or must one reach for pyparsing (or other parsing library)?
...
Hello, I am in progress to learn Python. Hopefully someone points me to correct way.
This is what I'd like to do below:
def decorate(function):
def wrap_function(*args, **kwargs):
str = 'Hello!' # This is what I want
return function(*args, **kwargs)
return wrap_function
@decorate
def print_message():
# I'd ...
in java, the following code defines an array of the predefined class (myCls):
myCls arr[] = new myCls
how can I do that in python? I want to have an array of type (myCls)?
thanks in advance
...
Please, help me with Python 2.6 and win32com.
I'm a newbie to Python and I got error
when I start the next program:
import pywintypes
from win32com.client import Dispatch
from time import sleep
ie = Dispatch("InternetExplorer.Application")
ie.visible=1
url='hotfile.com'
ie.navigate(url)
while ie.ReadyState !=4:
sleep(1)
print 'O...
I want to write a program that sends email using Python's smtplib. I searched through the document and the RFCs, but couldn't find anything related to attachments. Thus, I'm sure there's some higher-level concept I'm missing out on. Can someone clue me in on how attachments work in SMTP?
...