Questions tagged [python]

373289 questions
1

votes
1

answer
207

Views

Python command line arguments

I'm trying to accept command line arguments and place the values in a certain spot in my code I'm having trouble doing so.... hash = sys.argv[1] def on_timeout(self): print >> sys.stderr, 'Timeout...' return True # Don't kill the stream sapi = tweepy.streaming.Stream(auth, CustomStreamListener()) sa...
sirvon
1

votes
1

answer
181

Views

Child classes and parent classes in Python

I'm currently watching Bucky's Python Programming tutorials. He has explained the concept of child classes and parent classes, like so: class Dad: var1 = "Hey I'm Dad" class Mum: var2 = "Hey I'm Mum" class Child(Mum, Dad): var3 = "Hey I'm a Child" This, I understand completely. However, he then turn...
1

votes
1

answer
585

Views

Programmatically generate Django sqlsequencereset

How can I programmatically generate the SQL generated by Django's manage.py sqlsequencereset command?
Sean W.
1

votes
1

answer
2k

Views

Way to filter using a backref “length” with SQLAlchemy

I have a one-to-many relationship between two types of objects Message and URL. A relationship is defined in the class URL with a backref named "link" that points to Message. Is there a way to make a filter, while querying on Message, to find for example the Message that possesses less than n URLs ?...
Ketouem
1

votes
1

answer
4.5k

Views

Using Tkinter to export user input to a .csv file

I have a tkinter code setup that will give the user seven entry prompts, and a "Submit" button. I want to be able to export whatever the user types into the entry box, to a .csv file. I have used the Python tkinter docs, and many other resources, including this website, but cannot find an answer. Th...
saurusrexx
1

votes
1

answer
3.8k

Views

Numpy array: concatenate arrays and integers

In my Python program I concatenate several integers and an array. It would be intuitive if this would work: x,y,z = 1,2,np.array([3,3,3]) np.concatenate((x,y,z)) However, instead all ints have to be converted to np.arrays: x,y,z = 1,2,np.array([3,3,3]) np.concatenate((np.array([x]),np.array([y]),z))...
Forzaa
1

votes
2

answer
73

Views

Assigning multiple variables in Python line-by-line analysis [closed]

I'm writing something that analyzes a directory line by line in Python. Parts of my text follow this format: SMITH, JOHN (123) 456-7890 (134) 193-2495 (284) 282-6829 I want to assign the three phone numbers to three different variables (i.e. phone1, phone2, phone3) all associated with the person Joh...
user2662091
1

votes
2

answer
699

Views

needed: simple way to force json to decode to “normal” iterable python lists

I've stackoverflow a ton and never found the need to ask a question before, and while there are a lot of threads on this subject, I can't seem to find something that is easy and makes sense. If I have somehow missed something, please provide a link. Here goes: I am trying to pass lists back and...
domoarigato
1

votes
1

answer
3.6k

Views

Moving files to subdirectory programatically (without using unix mv command) [duplicate]

This question already has an answer here: How to move a file in Python 9 answers Is it possible to move by means of os.rename or shutil.move all the files in a directory to a a subdirectory of the same directory? For example if I have the following structure: Dir_1 File_1 File_2 subDir_1 can I get...
pafede2
1

votes
3

answer
1.2k

Views

How to host server from laptop?

I am trying to make my laptop a http server. For starters, I am running: "python -m SimpleHTTPServer 8080" I think I should be able to access this server at http://my.pub.lic.ip:8080 (I obtained my.pub.lic.ip from www.whatismyipaddress.com). However, this does not work. I do not know what the proble...
Arvind Haran
1

votes
1

answer
1k

Views

API call from one Django site to another

I'm pretty new to Python/Django but I have set up an REST API for one website (siteA.com), and would like another website (siteB.com) to be able to call this API and show some results. For this I have added the Django REST Framework and Django Auth2 Provider to siteA. I can now call the API using...
Michael Nieuwenhuizen
1

votes
1

answer
465

Views

Move an object a certain amount of pixels? - Python/Pygame

Let's say I have an object and I've stored its x position, y position and the angle that it's facing (from 0 to 359). How would I find out the x and y position that it would be in if it travelled 10 pixels, for example? I need this because I'm making a Pong game and I'm unsure of how to make the bal...
CalB2207
1

votes
2

answer
22.6k

Views

pySerial inWaiting returns incorrect number of bytes

I've got a simple program to test serial functionality. My serial device reacts to two inputs. If the user enters 'a', it responds with 'fg'. If the user enters anything other character/byte, it responds with 'z'. If I send 'b' to the serial device, it will return 'z' just fine. When I send 'a', it...
user791953
1

votes
2

answer
935

Views

Represent webcam video as stream of pixel arrays in Python

I'm wondering if there is a way to analyse each frame of my webcam video per second as an array of pixels. For example: So if my resolution of my webcam was 3 x 3 (it's not) the I would get a constantly refreshing list of this form(or close). pixel_list = [[(R, G, B), (R, G, B)], [(R, G, B), (R, G,...
lorde
1

votes
1

answer
5.3k

Views

Find module in anaconda for ipython

I"m in window and trying to use pyodbc with ipython , I did pip install pyodbc and I am able to see the package and pyodbc.py under this location .. C:\Anaconda\Lib\site-packages\sqlalchemy\connectors\pyodbc.py but when I tried to do import pyodbc ImportError : No module named pyodbc What am I...
JPC
1

votes
1

answer
344

Views

(Python 2.7) easygui.choicebox if else statement how to [closed]

I am trying to make a mac address spoofer in python for my mac as i find other software to be unnecessary advance/hard to understand. First i want a choicebox asking what device you want to spoof but i can not get the if else statement to work. The point if if coice is the first then input this valu...
David Kvindesland
1

votes
1

answer
2k

Views

django with mysql what does 'maximum number of connections'?

I am writting simple application which django that can be used internally inside my office. probably 1000 people i say. I dont have any session handling, user handling. It is just a store/view process in the django. What i understood? 1) django closes reopens the database connection on each request...
Whoami
1

votes
2

answer
3.1k

Views

How to work RTSP in python

I need to catch RTSP stream from my IP-camera for convert and streaming to site. First I wanted use ffmpeg, but have not found ffmpeg wrappers for python2.7. Who can help me?
DevellMen
1

votes
1

answer
2.7k

Views

How do I change my Content-Transfer-Encoding header in Python?

This is my code right now: from email.MIMEText import MIMEText body = "helloworld" msg = MIMEText(body, 'plain') msg['Subject']= subject msg['From'] = from_field['name'] + ' ' msg['Date'] = datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S %z') #other code here for connecting to SMTP conn....
TIMEX
1

votes
2

answer
570

Views

Python tcp socket client

I need to have a tcp socket client connected to a server to send data and receive. But this socket must be always on and i cannot open another socket. I have always some data to send over the time and then later process the answer to the data sent previously. If i could open many sockets, i think...
balsagoth
1

votes
2

answer
907

Views

Changing color of text in a tkinter window by using colorchooser in python 3 and tkinter

Try to choose the color of the then print it, the printing bit works just need to get the color part working. If you need to see more of the code just ask. def mColour(): color = colorchooser.askcolor() color_name = color[1] mlabel2 = Label(mGui,text=color).pack() messagebox.showinfo(title = "Colour...
Minigeek22
1

votes
3

answer
82

Views

What's the simplest way to write a program/script to remove the same string from the beginning of a bunch of file names? [closed]

I have a bunch of mp3's that all have a long title, followed by "part 3" or "part 4", etc. So it's like "aasasdfjklakjsdf - part 3" and "aasasdfjklakjsdf - part 4" and "aasasdfjklakjsdf - part 5" and so on. I have over 100 of these and I would like to simply remove the "aasasdfjklakjsdf - " part fro...
Tim
1

votes
1

answer
62

Views

Sharing resources across agents, across processes in grinder

Here is the requirement : In simple words, I have a static dictionary(say dictionaryX) in a class (say ClassX in shared.py file) that needs to be shared across multiple agents and multiple processes in grinder. How do I achieve this..? Any help would be greatly appreciated. Thanks in advance
kirti
1

votes
4

answer
3.5k

Views

How to use Django REST framework with a model with default value for foreign key?

Django==1.5.5 djangorestframework==2.3.8 I have a model with a Foreignkey: class Role(models.Model): name = models.CharField("Name", unique=True) def __unicode__(self): return unicode(_(self.name)) class Worker(models.Model): name = models.CharField("Name") role = models.ForeignKey(Role, default=1)...
Toff'
1

votes
1

answer
101

Views

Importing lists from another file

Currently I am programming something that uses lists. These lists are quite large and I was wondering if I can put them in a separate python file. Then import them. For example List1 = [] List1.append("Blah") List1.append("Blah1") List1.append("Blah2") List1.append("Blah3") I'd like to have that lis...
1

votes
1

answer
6.6k

Views

How to load PNG files with pygame.image?

I'm simply trying to load an image with pygame with that piece of code : import pygame myimage = pygame.image.load("bla.png") And I get the error : pygame.error: File is not a Windows BMP file Note that when I call pygame.image.get_extended() it returns 0. How can I fix that and get the other format...
kaldo
1

votes
1

answer
248

Views

coding (unicode) hex to octal

I read a text file, which has some characters like that '\260' (it means '°'), and then I add it to DB (sqlite3). After that, I try to get the information from DB, but the sql-query will be built with '\xb0'(it means '°' too), because I get this information from XML file. I try to replace hex ch...
user2973395
1

votes
1

answer
572

Views

Pandas read_table() thousands=',' not working

I'm trying to read in some population data as an exercise to learn pandas: >>> countries = pd.read_table('country_data.txt', thousands=',', header=None, names=["Country Name", "Area (km^2)", "Areami2", "Population", "Densitykm2", "Densitymi2", "Date", "Source"], usecols=["Country Name", "Area (km^2)...
mszep
1

votes
1

answer
1.8k

Views

using morris chart in django

I am trying to use a morris chart in django. morris chart requires a data in format $(Morris.Bar({ element: 'mchart', data: [ { y: '2006', a: 120 }, { y: '2007', a: 75 }, { y: '2008', a: 50 }, { y: '2009', a: 75 }, { y: '2010', a: 50 }, { y: '2011', a: 95 }, { y: '2012', a: 100 } ], xkey: 'y', ykeys...
Laxmi Kadariya
-1

votes
4

answer
72

Views

Dictionary n: n*n, n+1: n+1*n+1

Having trouble creating a dictionary that loops in term of n: n*n, n+1: n+1*n+1, and so on. It has to contain numbers between 1 and 10 in this form. d = dict () for n in range (1,10): dict[n*n] I cannot print the expected output. I have tried with {} as well to make it cleaner with no success (n:n*n...
CGG
0

votes
1

answer
39

Views

Looping over nested dictionary and delete if condition is not met (python)

I have a list of nested dictionaries: [{'a': 1, 'b': 'string', 'c': [{'key1': 80, 'key2': 'string', 'key3': 4033}, {'key1': 324, 'key2': 'string', 'key3': 4034, 'key4': 1}]}, {'a': 1, 'b': 'string', 'c': [{'key1': 80, 'key2': 'string', 'key3': 4033}, {'key1': 324, 'key2': 'string', 'key3': 4034, 'ke...
rororo
0

votes
0

answer
37

Views

How to compress rows after groupby in pandas

I have performed a groupby on my dataframe. grouped = data_df.groupby(['Cluster','Visit Number Final'])['Visitor_ID'].count() I am getting the below output : data_df.groupby(['Cluster','Visit Number Final'])['Visitor_ID'].count() Out[81]: Cluster Visit Number Final 0 1...
shreeja7
-2

votes
0

answer
27

Views

Reading Json file in python

I am new to python and I am trying to read my json file (from local) in python. But the output that i print is looking like this: C:\Python27\python.exe C:/Users/lehmdir/.PyCharmCE2018.3/config/scratches/one.py {u'color': u'Red', u'fruit': u'Apple', u'size': u'Large'} Process finished with exit code...
Aju Antony
-1

votes
1

answer
23

Views

Multiple functions in one graph

So, I have a numpy.ndarray called CT with shape (10, 500). Each row is a function and defined over the x-variables called Gm. Gm is a numpy.ndarray with shape (1,500). I need to graph the 10 functions in the CT matrix (as a function of Gm) in one graph and try the following: # consumption functio...
terman
0

votes
0

answer
22

Views

How to escape variable in a postgresql insert query into a python script?

I have an issue with a Python script and i cannot find answers into the web, or i cannot implement them or they doesn't work for me :/ I have a Python script and into it i have an INSERT query for a Postgresql database. This is the query : print('Insert Site') with conn.cursor() as cur: cur.execute...
Thomas MOREAU
3

votes
1

answer
66

Views

How to determine if numba's prange actually works correctly?

In another Q+A (Can I perform dynamic cumsum of rows in pandas?) I made a comment regarding the correctness of using prange about this code (of this answer): from numba import njit, prange @njit def dynamic_cumsum(seq, index, max_value): cumsum = [] running = 0 for i in prange(len(seq)): if running...
MSeifert
2

votes
1

answer
58

Views

allowing django-oauth-toolkit to issue jwt instead of random strings

I understand that django-oauth-toolkit is using oauthlib and oauthlib provides an example on the implementation of using jwt instead of random strings. However, I don't understand how I can get django-oauth-toolkit to issue jwt instead of random strings. Can anyone give an example implementation or...
Valerio Zhang
0

votes
0

answer
6

Views

How to put together two python script Pi3 Gpio

hello everyone i need it help coding with python. I have a Raspberry Pi3 and I have two script that make different function but i wanna putting to work together. The first one drive a pir sensor with a led as a output (when the pir go high it start to count down, given enough time to detect a person...
Elvy Collado
2

votes
0

answer
15

Views

XGBoost, handling continous and fixed data for loan dataset

Background: I am using XGBoost to develop a model to predict whether a particular loan will default or not. I have now included time-series data on Fico score, and other variables that change throughout time. Thus I have 13,202 unique loans but with over 300,000 rows with variable and fixed data. Qu...
Wolfy

View additional questions