Eclipse/PyDev, Python 2.6, Django 1.1
All is working in run mode. If I put debug point inside manage.py file, breakpoint worked. But when I putted it in any action method, it causes nothing :(
I would want to raise an exception as it's made in Python or Java --to finish the program with an error message--.
An error message could be returned to a parent function:
func readFile(filename string) (content string, err os.Error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", os.ErrorString("read " + filename + ": " + err)
}
return string(content), nil
}
but I want that it can be finished when the error is found. Would be correct the next one?
func readFile(filename string) (content string) {
content, err := ioutil.ReadFile(filename)
defer func() {
if err != nil {
panic(err)
}
}()
return string(content)
}
If I have a models.py like
class WidgetType(models.Model):
name = models.CharField(max_length=200)
class Widget(models.Model):
typeid = models.ForeignKey(WidgetType)
data = models.CharField(max_length=200)
How can I build in a set of built in constant values for WidgetType when I know I'm only going to have a certain few types of widget? Clearly I could fire up my admin interface and add them by hand, but I'd like to simplify configuration by having it built into the python.
Hi, I'd like to get the name of the song that iTunes is currently playing.
What API should I refer to?
I'd like to use that both for a dashboard widget or a Java/python application depending on what it is easier to use.
Do you have some references for me?
Thanks in advance,
Mario
If i have some code looks like this(Please ignore the syntax, i want to understand it without a specified language):
count = 0
def countDown():
count += 1
if __name__ == '__main__':
thread1(countDown)
thread2(countDown)
thread3(countDown)
Here i have a CPU with only one core, do i really need a lock to the variable count in case of it could be over-written by other threads.
I don't know, but if the language cares a lot, please explain it under Java?C and Python, So many thanks.
For the past few years I've been dabbling in object-oriented languages like Python and Ruby, but the OOP concept never really meshed with me. Right now, I'm eager to learn something based on a different paradigm.
How can I use sed to replace this line
char * path_list_[1] = { "/some/random/path" };
with this line
char * path_list_[2] = { "lib/foo", "lib/bar" };
in a file named source.c
Notes:
* The path is really random.
* Your solution should only change this line in source.c
* I'm only interested in a sed oneliner.
You can use this Python regex as a starting point:
text = re.sub('static const char \* path_list_\[1\] = \{ "[^"]*" \};',
'static const char * path_list_[2] = { "lib/sun", "lib/matlab" };', text)
I need to serve images securely to validated users only (i.e. they can't be served as static files). I currently have the following Python view in my Django project, but it seems inefficient. Any ideas for a better way?
def secureImage(request,imagePath):
response = HttpResponse(mimetype="image/png")
img = Image.open(imagePath)
img.save(response,'png')
return response
(Image is imported from PIL.)
Now when I run this command:
/usr/bin/python ~/google_appengine/appcfg.py update ~/cdn
I should write email and password.
And it is keeping some time, but after a day, I should write email and
password again.
How can I keep my auntification (email and password) for long time
(month, year)?
Lately I have been having my eye on evented I/O to tackle some of my web application problems. I have been looking at things as Python's Twisted, Ruby's Eventmachine, and Node.js.
Are there any other alternatives to these three, maybe in other languages as PHP ?
is it possible to build a full functional, small scaled website, without java or python or perl or php? and with xml files as simple data storage? therefore, i can move my website any where I want.....
any experiences like this to share?
thanks.
I want to turn on logging of all SQL statements that modify the database. I could get that on my own machine by setting the log_statement flag in the configuration file, but it needs to be enabled on the user's machine. How do you enable it from program code? (I'm using Python with psycopg2 if it matters.)
how can i keep the combobox on the form in j2me with out using frameworks?
i have tried this but it is not showing any drop down for selection.
ChoiceGroup CoursePOP = new ChoiceGroup ("Pop Up choice", Choice.EXCLUSIVE, new String[] {"Python", "J2ME","Symbian"}, null);
The following Ruby code
def a(b,c) b+c end
is the same as follows with Python
def a(b,c): return b+c
It looks like that ruby has the special stack that stores the final evaluation result and returns the value when a function is called.
If so, what's the name of the stack, and how can I get that stack?
If not, how does the Ruby code work without returning something?
Hi
Can anybody help me to know , in how many ways we can develop application for Android platform.The only one way that i know is through Java.Somewhere i read that other than Java like Python , Rails and Native C are also used to develop android application.Please help me if anybody knows it.
I'm using this example code to grayscale an image,but the result is not right:
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
imshow(BW)
Where to see how graythresh is actually implemented?
BTW,is there a reason for using matlab feels so alike with python?
Or is it known that graythresh doesn't work well for images with little spatial resolution(like 62*21 ones)?
Hello there,
I've offered an out-of-job girl to help her study programming (with an MCSD as the ultimate goal) - and she has no progrmming knowledge. The idea is that she'll study from books and I"ll help.
Help- I need a gentle introduction to programming book, very easy, very practical, very hands-on and up to date. Optimally would be for the .Net 4.0 MS enviornment (C#,Visual Basic) but other alternaitves (Jave, Python etc.) are OK.
I have install apache,php and mysql on Mac 10.8.1.
After this, in my web brower i type this, it give the error message
Not Found
The requested URL /News-2012-Academy-Awards-53.html was not found on this server.
Apache/2.2.22 (Unix) mod_fastcgi/2.4.6 mod_ssl/2.2.22 OpenSSL/0.9.8r DAV/2 PHP/5.3.13 with Suhosin-Patch mod_wsgi/3.3 Python/2.7.2 Server at clontarf.girlsacademy.com.au Port 80"
Please help me to solve it.
I'm interested in learning about the alternative patterns to Model-View-Controller, specifically the Model-View-Adapter and Application-View-Controller patterns.
Google results tend to be either a high-level overview or Java-based.
Can anyone either provide, or point me to, an example of these patterns in either PHP, Python or JavaScript?
I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided I'm limited by not being fluent in C. However I cannot imagine working in a language without lists and hashes, maybe I'm just jumping a gun, but surely there are 'standard' collection libraries. I do not see any in the GNU standard lib though, any suggestions?
Hi guys,
I am a newbee to django and jython. I need to create and save image thumbnails in database. I am using django running on jython and mysql database. I was exploring python imaging library, but the i found out that i wont work with jython.
How do i create image thumbnails using jython and then save them in mysql db?? Any kind of help will be appreciated. thanx
I'd like to write small scripts which feature incremental search (find-as-you-type) on the command line.
Use case: I have my mobile phone connected via USB, Using gammu --sendsms TEXT I can write text messages. I have the phonebook as CSV, and want to search-as-i-type on that.
What's the easiest/best way to do it? It might be in bash/zsh/Perl/Python or any other scripting language.
I know how to print "all" global variables using the following code
for k,v in pairs(_G) do
print("Global key", k, "value", v)
end
So my question is how to do that for all variables that are accessible from the currently executing function, something that can do what locals() does for Python.
Even though we have languages like C++, Java, Python etc., why is COBOL still a preferred language in the business world?
EDIT:
Why was it so popular?
Sorry for not creating a separate thread for this question.
I've committed myself to diving into vim to become faster at writing code for ruby/python and I'm having a hard time navigating around files.
Mainly, I'm referring to switching between insert mode and navigation modes. Maybe I'm just not completely used to the editor yet but it feels very awkward to constantly be switching in and out of insert mode.
Is this something that will go away with time? Are there any tricks to getting quicker at moving in and out of insert mode?