Python is a dynamic, high-level language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules, exceptions, had an extensive standard module library. Python can also be embedded in other ...

learn more… | top users | synonyms (1)

0
votes
1answer
72 views

using one database connection across multiple functions in python

whats the best way to go about this in python? I have a number of like so def test1() .... code ..... def test2() .... code ..... def test3() .... code ..... how could I create one ...
-1
votes
1answer
78 views

How to put a .py file on a web host and use it in the command prompt?

So I have a python file that runs a method when it opens a file. Ie. my python.py file opens test.txt and puts it data into another file. The test.txt file is on my local PC, but I want the ...
-6
votes
2answers
67 views

Why C=A.append('1') doesn't work in Python

A=['1'] C=A.append('1') print C Why is the above code return None but not ['1', '1'] in Python ?
0
votes
0answers
24 views

python: area mapping using trigonometric circle

I have a car controlled by a raspberry pi, I would like to create maps to each place it visits. The solution I came up with is simple. Lets say you tell the car to go forward and then after 5 minutes ...
29
votes
6answers
19k views

'import module' vs. 'from module import function'

I have always been using this method: from sys import argv and use argv with just argv. But there is a convention of using this: import sys and using the argv by sys.argv The second method ...
102
votes
15answers
16k views

Is it always a best practice to write a function for anything that needs to repeat twice?

For myself, I can't wait to write a function when I need to do something more than twice. But when it comes to the things that only appear twice, it's a bit more tricky. For code that needs more than ...
-6
votes
0answers
60 views

How do I invoke a for loop in a method with argument “self” [on hold]

def commandType(self): '''P.commandType() -> str ''' for i in self: ......... I want to write a for loop such that I am able to loop through the Contents of "P" object. ...
2
votes
3answers
136 views

Is it good Python style to write a function that has no effect other than potentially raise exceptions?

Sometimes I find myself writing Python code that looks like this: def check_stuff(param): if condition1(param): return "condition1" # These might be enum values, etc., instead of strings ...
0
votes
0answers
18 views

Strategy for “multi-level equality” test

It is well-known that Lisp supports multi-level equality test. I want to implement similar multi-level equality test on a custom class in Python. I know that I can (and should) override the __eq__, ...
0
votes
0answers
5 views

Input to list and opperate on [migrated]

I've just started with Python (3.), and while it is fairly easy to pick up, I'm trying to learn how to work with lists. I've written a small program which asks for the amount of numbers to input, ...
0
votes
0answers
37 views

web requesting - time competition - javascript? [on hold]

first of all, I would like you to excuse my english and description of the problem. I am not english native speaking, so I am trying my best.... Before you say, that is am abusing some server- I need ...
-4
votes
0answers
40 views

My trying to make the program decrement every 1 second. It keeps printing 99. What did I do wrong? [closed]

# SimpleGUI program template # Import the module import simplegui # Define global variables (program state) countdown = 100 # Define "helper" functions def blast_off(): global countdown ...
0
votes
0answers
62 views

Best strategy for converting change in longitude and latitude to north, south, east, west in degrees

This is not a class assignment but a conceptual question I'm struggling with for a personal project. I need to convert a large paired group of long and lat coordinate values that show a ...
2
votes
2answers
798 views

Front-end structure of large scale Django project

Few days ago, I started to work in new company. Before me, all front-end and backend code was written by one man. As you know, Django app contains two main directories for front-end: /static - for ...
1
vote
1answer
241 views

Merge two different API calls into One

I have two different apps in my django project. One is "comment" and an other one is "files". A comment might save some file attached to it. The current way of creating a comment with attachments is ...
-2
votes
1answer
29 views

Does datetime.fromtimestamp() return a datetime object or a string?

Basically what the title says. This is a more theoretical question than anything, I don't have a specific use for it. I've looked up the documentation and I can't find a definite answer.
-4
votes
0answers
49 views

Where can I learn more python [closed]

I am a beginner programmer and I've been learning Python for about a month now. I feel like I'm not really going anywhere with it and would like to know what would be the best place or course of ...
0
votes
1answer
92 views

How to structure GUI program with a database

I am fairly experienced with web design and programming, C, C++ and a little java (used it to build some small GUI). I am trying to work with Python, and I am faced with some technical structuring ...
0
votes
0answers
5 views

How do I read an exe file into ram then launch it from Python? [migrated]

My goal is to encrypt my exe file for distribution and store it in a python decrypting launcher. When the python launcher starts, it will use a key to decrypt the app and write the exe to ram. I then ...
-1
votes
0answers
30 views

How to create “fuzzy” material design type shadows on a canvas? [migrated]

I can't seem to find out how shadows are created in material design, or how css does it. Specifically, I am curious how, if given a canvas, one would create the 'blur' part, using algorithms. Below is ...
1
vote
1answer
50 views

Technique to synchronize error codes in a same-project-API

In the project I am working right now, we have some python and some C# code. At some point, I call from python a subprocess which starts a C# executable. This C# code returns an error code, which has ...
-2
votes
0answers
113 views

Printing in Python — inherently functional? [migrated]

Learned Python for a project at work (which is cool, b/c now I can fiddle with Anki!). In general, I really like the language. Not as intense as Perl, and although I haven't played with its ...
2
votes
0answers
350 views

How does the Zope Component Architecture (ZCA) relate to Service Component Architecture (SCA)?

I'm very new to the principle of Service Component Architecture and Zope in general, but the more I look, the more ZCA seems to be a good solution for a certain class of problems I often encounter. I ...
-1
votes
0answers
12 views

How to plot upper limits on only certain data points with python? [migrated]

So I have two arrays, one of wavelengths and one of magnitudes. Some of the magnitudes are upper limits. These upper limits are always fewer characters that the actual measured values so I figured I ...
9
votes
11answers
6k views

Do I have to learn html and javascript to create web applications? [closed]

I am an experienced Java programmer, and I want to create a complex web application requiring dynamic pages, drawings, etc (take SO as an example). Do I have to learn javascript/html in order to ...
-2
votes
0answers
29 views

need help python geo-spatial script [migrated]

new to this and glad to be here. I have a python script that I am working on, and the scripts main purpose is to take a list of cities from a .txt file on my computer, and have the script spit out a ...
1
vote
3answers
97 views

Which part of the code should rewind a file pointer?

If you had a function that took a handler to a file and then performed some actions that moved the pointer, would you expect it to put the pointer back when it was finished? Additionally, would you ...
0
votes
1answer
33 views

Is it reasonable to use a decorator to instantiate a singleton in Python?

Suppose I have a class like this: class Foo(object): # some code here As it happens, Foo is a singleton. There are numerous ways to write singletons in Python, but most of them don't really ...
0
votes
0answers
20 views

How to run a function after returning 201 view [migrated]

I'm using the Django Python framework with the Django REST Framework. When a new instance of a model is saved, I need to generate a PDF that is saved locally on the server. Is there a way that I can ...
1
vote
2answers
149 views

Should I prefer Python generators to lists?

Python iterators can be very memory efficient. Should I always prefer to use generators instead of just lists? In what situations should I prefer a plain array? For example instead of this: emails = ...
0
votes
0answers
28 views

Finding the largest bundle of flagged points

I am currently working to develop a program that takes in an array of 4 columns and around 200,000 rows. Each column represents x, y, z (coordinates), and a flag denoting whether or not this point is ...
-2
votes
0answers
9 views

International characters in pyodbc - ODBC python library [migrated]

I'm using pyodbc to connect to my *.mdb files and store them in a sqlite / spatialite database for further work and analysis. I'm passing DSN like this: ...
2
votes
1answer
85 views

First stab at python classes… when do I need 'self'?

Could someone look over this and let me know if i've butchered anything. It's just a simple class definition in python, but I don't have any local devs to make sure I'm using the language right. ...
3
votes
2answers
91 views

What is the relationship between scope and namespaces in Python?

In many resources I found "scope" and "namespaces" are used interchangeably, which seems a bit confusing since they mean different things. Scope defines the region of the code where a name is ...
2
votes
1answer
79 views

Tree search for path finding - algorithm critiques

So, I'm pretty new to AI in general, and am trying to implement a tree-based search from a textfile input (a maze). An example would be: |||||||||||||||||||||| | || | | | \ | |||||| ...
5
votes
3answers
764 views

Can “higher order function” feature allow/maintain abstraction and encapsulation?

Below is the function repeat written using a functional paradigm, such that when called as repeat(square, 2)(5) it will apply the square function 2 times on the number 5, something like ...
1
vote
1answer
130 views

Is circular Dependency Injection a good practice?

I'm trying the Dependency Injection pattern in some new classes, more specifically in a Transaction System and stumbled into a dilemma. I have a Person class with a create_new_transaction method, and ...
0
votes
0answers
28 views

Structuring a multi-language project?

Let's say I'm working on a project which involves writing code for multiple devices, each in its own language (in particular, Arduino and Python). I want to contain the entire project in a single ...
3
votes
1answer
652 views

Chatbot Conversation Objects, your approach?

I'm a nub programmer, using python, and my current project is a chatbot for an irc channel I reside in. I wish to make it capable of keeping conversations organized, primarily between its self and one ...
3
votes
0answers
370 views

Why is an inline if/else faster than a .get() in Python? [migrated]

I was reviewing some code earlier and the developer wrote an inline if/else rather than a get() to retrieve an element from a list if it exists (otherwise give it a default value). I decided to spring ...
0
votes
1answer
88 views

Facing MemoryError in Python

I wrote a program to find prime factors of a number. When I give a large number(600851475143) as input, MemoryError pops up. Below is the code: def fact(a): factors = [] for i in ...
7
votes
2answers
227 views

How to efficiently store big time series data?

I need to store and to be able to query some very large amounts time series data. Properties of the data are as follows: number of series : around 12.000 (twelve thousand) number of data points, ...
-1
votes
1answer
115 views

Execute python code without showing the code

I want to use exec to execute python code (using the byte code, instead of the raw text that python will interpret). It's all for a competition where you can see the code of the other competitors, I ...
-1
votes
1answer
115 views

Python: Faster to use global variable or pass as arguments to a function? [duplicate]

Hey so i was wondering which is the more efficient way, or better practice to do in this situation. 1, def function(): global number number += 2 Or 2, def function(number): return ...
0
votes
1answer
181 views

Simple unicode application?

I want to create simple language learning applications to help friends in learning languages. A simple Java console application would do the trick, but the Windows console does not seem to handle ...
-3
votes
0answers
14 views

Turn off printouts in bottle server [migrated]

I am running a web server with the bottle package I got from bottlepy.org. I start the server with run(host=localhost, port=8080, debug=False) But the server keeps printing information on the ...
0
votes
2answers
38 views

Iterating a function with a static argument: Global functions + lambdas vs internal function?

I am never sure which of these is better form: Option A def a(x,y): def b(z): return z+y return map(b, x) print a([10,20], 5) Option B def b(z,y): return z+y def a(x,y): return ...
0
votes
0answers
22 views

Need to add websocket support to a single page that's running a wsgi service

Current setup. I have a legacy ERP system (Thoroughbred) and i then have several in house applications (CRM, WMS) and a website that interact with it via an xml server and straight ODBC connections. ...
0
votes
2answers
84 views

Empty except block vs. huge except block

Which of these is easier to read? An empty except block: try: foo = do_foo() except FooError: pass # see below else: return do_bar(foo) # Recover from the FooError (long, complicated) ...
4
votes
3answers
391 views

Why do python generators and functions share the “def” keyword?

Consider the following: def some_function(): return 1 def some_generator(): yield 1 In the code above, some_function is a function, while some_generator is a generator. They look quite ...