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)

-2
votes
1answer
23 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
27 views

Where can I learn more python [on hold]

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
84 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 ...
-4
votes
0answers
34 views

Expanded explanation of conditional statements in Python [on hold]

Can someone provide a resource that gives a detailed breakdown of conditional statement components? For instance. Here's a fragment: def the_term_here(): if 1 < 2: print "great" ...
-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 ...
0
votes
1answer
47 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 ...
-1
votes
0answers
20 views

UML Sequence Diagram generator for working Python code [closed]

I'd like to look at some working Python code in terms of UML sequence diagrams for better understanding. Now I have to draw this diagrams with my pen - it's too slow. And I know that Python 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
333 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 ...
-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 ...
-5
votes
0answers
32 views

How to replace characters in a string using a dictionary [closed]

Python sort-of newbie here! I'm trying to figure out how to properly replace characters in a string using a dictionary. I do know of the re library but I'm just trying to see how to best do that but I ...
0
votes
1answer
32 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 ...
1
vote
3answers
92 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
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 ...
0
votes
0answers
25 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
82 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. ...
1
vote
2answers
144 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 = ...
5
votes
3answers
757 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 ...
2
votes
1answer
76 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: |||||||||||||||||||||| | || | | | \ | |||||| ...
3
votes
2answers
88 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 ...
0
votes
0answers
27 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
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 ...
1
vote
1answer
123 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 ...
-1
votes
1answer
111 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
106 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 ...
-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
36 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
21 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
83 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
384 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 ...
0
votes
1answer
47 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
1answer
195 views

Any reasons NOT to write self testing Python code?

Whilst writing tests I was giving considerable thought to the question of how to ensure I have tests for every class in my application. It occurred to me that maybe I should just put the test code ...
1
vote
1answer
65 views

Allow user to enter DSL, rules or code?

I have a python library that allows me to define rules by chaining inputs and outputs of functions ( producer(grep(count( [print(),log() ] ))) This functions define a pipeline from left to right. ...
-2
votes
3answers
113 views

How to manage a large list of distinct numbers

I have a list of around 2 billion distinct numbers stored in memory for some computation. Currently, every time I need to add a new entry I have to search the entire list for a potential duplicate. ...
0
votes
0answers
10 views

I want use “isinstance” to judge what type object people input from keyboard [migrated]

This is my code num = input() if not isinstance(num,int): print("wrong input") num = input() However if I type letters from keyboard,the computer gives this error: please input a num q ...
4
votes
1answer
53 views

Should I use exceptions to control the range of parameters in Python?

For example for the following method signature: def genClusters(n_clusters, n_nodes, cluster_distribution): n_clusters should be an integer of more than 1. n_nodes should be an integer of more ...
0
votes
0answers
29 views

moving Data mining model from “lab” to production environment

I am designing the architecture of an analytics system . I have a data mining ensemble model developed in scikit learn . I want to move this to the production environment so the new incoming data can ...
1
vote
1answer
31 views

Is there a standard project metadata / dependency file for Python?

In my Node.JS projects, I save my project metadata into package.json: dependencies, version number, author, description, and so on. This makes it so anyone can clone my project and run npm install to ...
0
votes
0answers
30 views

Persist data downloaded by Celery workers

I'm working in a tool that downloads tweets from Twitter to process them later. For this purpose I'm using Celery with RabbitMQ, sending task with the keywords that must be tracked by the workers. My ...
0
votes
0answers
31 views

Improve communication between controller and trackers in a Twitter fetcher tool using RabbitMQ or Apache Flume

I've been working for a time with some researches developing a tool to fetch tweets from Twitter and process them in some way. The first prototype "worked" but became a pain as we used sockets to ...
2
votes
3answers
338 views

Multiple users using the same script for their websites

I'm working on a project, I have a question regarding the architecture: Say I have a many python scripts on my server and there's main.py which contains all the classes. And there's a script called ...
0
votes
1answer
35 views

Should I have all models done before I syncdb?

I'm not sure if I want to add more attributes to my models or create another model. I've coded up to the point where I need to syncdb to start using some data in the site, but I'm hesitant to do it. ...
0
votes
0answers
37 views

Is there a standard practice on making a modular Python script?

I wrote a Python script for PIA here: pia-auto-login.py However, I need to make it more modular so that it does the OpenVPN changes from this script. Then I want to create two more packages (at ...
0
votes
1answer
72 views

Using a bytearray rather than a string to store password in memory

Using a bytearray datatype to store a password (in memory) has an advantage over using a string datatype for a password in that a bytearray is mutable and can be overwritten with 0x00 values when the ...
0
votes
1answer
75 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 ...
8
votes
4answers
304 views

why empty function are needed

I started learning python and I am wondering why empty function are needed in a programming language e.g. in python: def empty_func(): pass even in shell scripts empty function empty functions ...
96
votes
14answers
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 ...