I want to send a datetime.datetime object in serialized form from Python using JSON and de-serialize in JavaScript using JSON. What is the best way to do this?
I need to upload an image and then preview it without posting back as i need to have a file upload control(even HTMLinputfile or ASPfileupload) then the user will browse to select image after selecting (browsing) there will a button(HTMLInputButton) that will save the uploaded image and preview it.
I have the following code :
<div>
<input id="UploadInput" type="file" value="Upload" />
<br />
<input id="PreviewBtnInput" type="button" value="Preview" onclick="ShowPreview()" />
<br />
<img id="ImgUploaded" />
</div>
So how can i do this task ?
Thanks in advance for any reply but please if any one has a link for article that talk about this issue please i need a clear code not article details.
Hi! I am interested in saving and load objects using the pickle module as you can read in a question I asked before:
Python: Errors saving and loading objects with pickle module
Someone commment:
1, In an other way: the error is raise because pickle wanted to load an instance of the class Fruits and search for the class definition where it was defined, but it didn't find it so it raise the error
Now I want to save and load a class definition in order to solve the problem I describe in the question mentioned before.
Thank you so much!
Python is filled with little neat shortcuts.
For example:
self.data = map(lambda x: list(x), data)
and (although not so pretty)
tuple(t[0] for t in self.result if t[0] != 'mysql' and t[0] != 'information_schema')
among countless others.
In the irc channel, they said "too many to know them all".
I think we should list some here, as i love using these shortcuts to shorten & refctor my code. I'm sure this would benefit many.
I have a few questions about python
I've seen many pages like these on Google
http://mail.google.com/support/bin/answer.py?answer=6583
https://www.google.com/adsense/support/bin/topic.py?topic=13488
...that have .py extensions. 1: Are pages like these built on pure python code, but printing out html like print "<div etc..." or like the typical asp,jsp,php type of pages with html pages and embedded python code like:
<html>
<% some python code %>
</html>
2: What is python mainly used for making? windows apps or web or .. ?
3: Are ruby and perl also similar to python?
Is there a general convention about exposing members in Python classes? I know that this is a case of "it depends", but maybe there is a rule of thumb.
Private member:
class Node:
def __init__(self):
self.__childs = []
def add_childs(self, *args):
self.__childs += args
node = Node()
node.add_childs("one", "two")
Public member:
class Node2:
def __init__(self):
self.childs = []
node2 = Node2()
node2.childs += "one", "two"
Hello everyone,
How can I get the file name and line number in python script.
Exactly the file information we get from an exception traceback. In this case without raising an exception.
This whole topic is way out of my depth, so forgive my imprecise question, but I have two computers both connected to one LAN.
What I want is to be able to communicate one string between the two, by running a python script on the first (the host) where the string will originate, and a second on the client computer to retrieve the string.
What is the most efficient way for an inexperienced programmer like me to achieve this?
What is the most effective and compatible automatic Python obfuscator? What are your experiences with using each?
And before anyone asks why I am obfuscating -- I am doing it simply because I can. Thanks.
I have issue where i want to create Dynamic function which will do some calculation based to values retrieved from database, i am clear with my internal calculation but question in how to create dynamic class:
My Structure is something like this :
class xyz:
def Project():
start = 2011-01-03
def Phase1():
effort = '2d'
def Phase2():
effort = '3d'
def Phase3():
effort = '4d'
Now want to generate those all PhaseX() function dynamically so can any one suggest me
how to achieve such thing using Python Code
Waiting for Positive reply
Regards
Thank You
I write a python class which makes asynchronous method calls using D-Bus. When my reply_handler is called, it stores data in list. This list can be used by another class methods at the same time. Is it safe or I can use only synchronized data structures like Queue class?
Hi, I'm developing C extensions from python ad I obtain some segfaults (inevitable during the development...).
I'm searching a way to display at which line of code the segfault happens (an idea is like tracing every single line of code), how I can do that?
What are the differences between these built-in Python data types: list, sequence and slice? As I see it, all three essentially represent what C++ and Java call array.
I want to run a cmd exe using a python script.
I have the following code:
def run_command(command):
p = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return p.communicate()
then i use:
run_command(r"C:\Users\user\Desktop\application\uploader.exe")
this returns the option menu where i need to specify additional parameter for the cmd exe to run. So i pass additional parameters for the cmd exe to run.
How do i accomplish this. I've looked at subprocess.communicate but i was unable to understand it
Hi everyone,
I have two python cgi pages (index, display), what i need to do is calculate time frame between the execution.
Work flow:
Index.py (submit)
After submit it redirect to display.py page
display.py page has got class with execute(),display() &init_main() functions
In init_main() i have created class object which access to above functions
I need to calculate time interval between the submit (index.py) to execute() end, so i can show user how much time does different weighted file takes on real time.
Hoping to see your suggestions
Thanks
Hi,
Fastest way to uniqify a list in Python without preserving order? I saw many complicated solutions on Internet - could they be faster then simply:
list(set([a,b,c,a]))
?
I'm trying to write a function named median that takes a list as an input and returns the median value of the list.
I'm working with Python 2.7.2
The list can be of any size and the numbers are not guaranteed to be in any particular order.
If the list contains an even number of elements, the function should return the average of the middle two.
This is the code I'm starting with:
def median(list):
print(median([7,12,3,1,6,9]))
Hello everyone, i'm looking for a way in python to run an external binary and watch it's output for: "up to date" If "up to date" isn't returned i want to run the original command again, once "up to date" is displayed i would like to be able to run another script. So far I've figured out how to run the binary with options using subprocess but thats as far as I've gotten. Thanks!
How can I parse text and find all instances of hyperlinks with a string? The hyperlink will not be in the html format of <a href="http://test.com">test</a> but just http://test.com
Secondly, I would like to then convert the original string and replace all instances of hyperlinks into clickable html hyperlinks.
I found an example in this thread:
Easiest way to convert a URL to a hyperlink in a C# string?
but was unable to reproduce it in python :(
Suppose user enter this string at terminal
123 456 456 //then hit enter
How do I scan these three (could be more) numbers in different variables in python
Could be something like this:
for i in range(1,n)
m[i]=#WHAT FUNCTION SHOULD I PUT HERE
In c++ we can easily use cin>>m[i] inside above loop to scan the variables.
If i use input() or raw_input() , they would scan whole line in single variable.
I have written a simple python module, it has this code:
_log = logging.getLogger("mymodule")
_started = False
def set_log_level(level):
_log.setLevel(level)
if not _started:
_hdlr = logging.FileHandler('mymodule.log')
When I call set_log_level() program fails because symbol _started is not found. It is normal because global _started is missing in the method. But my question is: symbol _log has the same visibility as _started, so why does this symbol can be found?
BR,
// Toby
Hi,
I'm use nosetests to run some tests. However, after the tests have finished running, the nosetests process just sits there, and will not exit. Is there anyway to diagnose this? Does Python have a facility similar to sending Java a kill -QUIT which will print a stack trace?
I have a text document that contains a list of numbers and I want to convert it to a list. Right now I can only get the entire list in the 0th entry of the list, but I want each number to be an element of a list. Does anyone know of an easy way to do this in Python?
1000
2000
3000
4000
to
['1000','2000','3000','4000']