|
How do you convert a python time.struct_time object into a datetime.datetime object? I have a library that provides the first one and a second library that wants the second one...
Started by static_rtti on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
In localtime) into seconds since the Epoch, then use datetime.fromtimestamp() to get the datetime object.
|
|
I've got a list of Python objects that I'd like to sort by an attribute of the objects themselves. The list looks like:
>>> ut [<Tag: 128>, <Tag: 2008>, <Tag: <>, <Tag: actionscript>, <Tag: addresses>, <Tag...
Started by Nick Sergeant on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
However,....
Update : Although this method would work, I think operator.attrgetter("count") .
See rich comparison in python .
More on sorting by keys »
Add rich comparison operators to the object class, then use sort() method of the list.
|
|
I am trying to get a conceptual understanding of the nature of Python functions and methods. I get that functions are actually objects, with a method that is called when the function is executed. But is that function-object method actually another function...
Started by DavidG on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Read: http://diveintopython....
:) Thinking of a function as an object is certainly the better answer in Python itselfYour question is "is python function like a class with only _ init _?"? Yes, something like that, but more simple.
Of it.
|
Ask your Facebook Friends
|
I'm seeking advice on doing the following in a more pythonic way.
Consider:
class MyObj(object): def __init__(self): self.dict_properties = {}
Suppose I've got a list which contains multiple MyObj instances:
mylist = [<__main__.MyObj object at 0x10...
Started by ChristopheD on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
You could reach for operator and try to compose an attrgetter... .
Mylist.sort(key=lambda x: x.dict_properties['mykey'])
is way simpler, and faster.
I'd just do:
mylist.sort(key=lambda o: o.dict_properties["kykey"])
You could also overide cmp on the class .
|
|
I remember that at one point, it was said that Python is less object oriented than Ruby , since in Ruby, everything is an object. Has this changed for Python as well? In the latest Python, is it more object oriented than the previous version?
Started by Jian Lin on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Python's way means just one function to remember
Hold on, both Ruby and Python://docs.python.....
There's more for a particular object.
I'm not sure that I buy the argument that Ruby is more object-oriented than Python.
|
|
I need to convert a python code into an equivalent java code. Python makes life very easy for the developers by providing lots of shortcut functionalities. But now I need to migrate the same to Java. I was wondering what will the equivalent of dict objects...
Started by Chantz on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
From this article that offers a good side by side view of python/java
The Jython analogues to Java's collection.
|
|
Is there a library method to copy all the properties between two (already present) instances of the same class, in Python? I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()
Thanks!
Started by Joril on
, 6 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Python is not meant to be fast, it's meant to be readable a class attribute something like :....
A shallow copy
If you use python properties you should look at inspect.getmembers() and filter out, it will get garbage-collected immediately).
|
|
1 import sys 2 3 class dummy(object): 4 def __init__(self, val): 5 self.val = val 6 7 class myobj(object): 8 def __init__(self, resources): 9 self._resources = resources 10 11 class ext(myobj): 12 def __init__(self, resources=[]): 13 #myobj.__init__(self...
Started by echamber on
, 8 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
You have to avoid using a mutable object on the callimport sys class dummy(object): def __init__(self, val): self.val = val class myobj(object): def value is evaluated at function....
Resources
This is a known Python gotcha .
|
|
Is there an easy way to call Python objects from C#, that is without any COM mess?
Started by Meidan Alon on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You would do this if you need to use Python libraries that you don'....
2) Expose your Python functions to COM.
I know of 3 ways:
1) Use Iron Python, and your Python projects can interact freely with projects written in C#.
|
|
How can I check if a Python object is a string (either regular or Unicode)?
Started by Matt S. on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
To check if an object o also What’s the canonical way to check for type in python?
I might deal with this in the duck or unicode type, real_word will hold its value....
Docs.
Use isinstance(obj, basestring) for an object-to-test obj .
|