|
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 want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this:
>>> library = Library() >>> library...
Started by cool-RR on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Check here:
http://rudd-o.com/projects/python(ChangesMonitor,object): one_val ....
It sounds like you're describing the observer pattern.
To store a name:hash pair for each object, then use the pickle module to save the dictionary.
|
|
Having a background in Java, which is very verbose and strict, I find the ability to mutate Python objects as to give them with fields other than those presented to the constructor really "ugly".
Trying to accustom myself to a Pythonic way of thinking...
Started by Beau Martínez on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
So the following is better than simply having an empty __init__ method (you’ll also get a higher pylint score for that):
class Blah(object): def with this approach is, that your object....
You’ll easily see what properties your object has.
|
|
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'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 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.
|
|
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#.
|