Questions tagged [python-2.7]

23286 questions
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
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
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
-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
-4

votes
2

answer
80

Views

AttributeError: 'unicode' object has no attribute XXX

I'm trying to use pipl. I want to get the info from a mail and save it into a Excel file. from piplapis.search import SearchAPIRequest from piplapis.search import SearchAPIError from openpyxl import load_workbook request = SearchAPIRequest(email=u'[email protected]', api_key='......') try: resp...
SoftTimur
1

votes
1

answer
714

Views

Python: How to remove \n from a list element 2D?

I have a problem, in a 2D list: t = [['\n'], ['1', '1', '1', '1\n']] I want to remove the "\n" from the nested lists.
try setyo utomo
0

votes
1

answer
18

Views

How to format the irregular datetime strings

I am getting a datetime format like '2019-12-02 12:400:00", "2019-12-02 120:4p:00" from a api call. How to format it to make it proper date time format.
Balasubramanian Raju
1

votes
2

answer
1.4k

Views

Get Attribute of xml using python etree

Here is my xml . . . . I want to get attribute of this xml using orgID. Suppose orgID=1234 then output should be This is Demo Name What i have tried , import urllib2 import lxml.etree as ET url="url goes here" xmldata = urllib2.urlopen(url).read() root = ET.fromstring(xmldata) print root.xpath('//D...
1

votes
1

answer
1.6k

Views

can't install reportlab mac OS X 10.9.2 + python2.7

I'm struggling to install reportlab on mac OS X 10.9.2 with python 2.7. I managed to install it using pip3 even if I need it for python2.7 so I believe I have all the required packages installed. Can you please help? Here is the install log (If you need the full unstripped log, just ask): $>pi...
koleror
1

votes
1

answer
920

Views

Django/Tastypie - DELETE requests deleting everything

I have the following model class Open(models.Model): name=models.TextField() opened=models.DateTimeField(auto_now_add=True) user=models.ForeignKey(User) and the following resources class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name = 'user' class OpenResource(...
user3264316
1

votes
1

answer
799

Views

how to traverse a unicode tamil word character by charcter in python?

I want to know how many characters are there in a Unicode string (Tamil) and then check the character1 and character2 for particular occurrences. I am able to split the word into characters, but I do not know how to traverse through them character by character using the word length. Example : word...
charvi
1

votes
1

answer
130

Views

Why does this command fail to print the correct exit code of a Python command?

In a cmd.exe window, when I run python -c "exit(12)" and then run echo %errorlevel%, it prints 12. After that, when I run python -c "exit(13)" & echo %errorlevel%, it prints 12. Why does the second command fail to print the correct exit code?
userpal
1

votes
4

answer
55

Views

How to take multiple lists and nest them?

Currently working with a text file that is read into python and then must be made into lists with a list (nested I guess?) So far I've tried double splitting the file but to no avail. This is what the reader code looks like: def populationreader(): with open("PopulationofAnnecy", "r") as in_file: fo...
Johnathan Scott
1

votes
3

answer
93

Views

Rounding Up a Number in Python

I am trying to round up a number using math module in python. So when I do, print math.ceil(21/10) I get '2.0' which is right. print math.ceil(27/10) I still get '2.0' I want to get 3, since it is closest to 2.7 Could someone please advise a workaround. Thanks in advance.
Md. Mohsin
1

votes
1

answer
2.2k

Views

Custom time series resampling in Pandas

I have a df with OHLC data in a 1m frequency: Open High Low Close DateTime 2005-09-06 18:00:00 1230.25 1231.50 1230.25 1230.25 2005-09-06 18:01:00 1230.50 1231.75 1229.25 1230.50 . . 2005-09-07 15:59:00 1234.50 1235.50 1234.25 12...
hernanavella
1

votes
2

answer
2.8k

Views

Extracting variables from gridded netcdf data into ASCII

I would like to know if anyone has any experience extracting information from gridded climate data and organizing it in a way that would be easier to work with to produce a time series. I am not sure how to use the indices (i and j or lat and lon, respectively) and I would like to only select data f...
user3275006
1

votes
1

answer
3.2k

Views

Adding a crosshair or marker to a matplotlib contour plot

I am plotting an NumPy array as a contour plot using matplotlib: import numpy as np import matplotlib.pyplot as plt plt.contour(array, linewidths = 1, colors = 'k') plt.contourf(array, cmap = plt.cm.jet) plt.colorbar() plt.show() I would like to add a 'crosshair' or other marker to denote the maximu...
El Confuso
1

votes
1

answer
1.1k

Views

Reading a .doc extension file ,ElementTree

I have successfully read .docx files using ElementTree package using zipfile. But I realized that there isn't the archive 'word/document.xml'for .doc files . I looked into the docs but did not find any. How can it be read? For docx, i used : import zipfile as zf import xml.etree.ElementTree as ET z...
Hypothetical Ninja
1

votes
2

answer
678

Views

Iterating Over Xml using findall , Lxml

I have the following xml : Hello there See you there .. I want to extract all text with the highlight "red" value. Note that highlight tag is one level down to that of the text tag. And the conditions are: For every paragraph , add an extra space . If the break tag is encountered whilst iter...
Hypothetical Ninja
1

votes
1

answer
545

Views

Get spline fit residual from scipy.interpolate.splprep()

I am using the interpolate package from scipy. In the documentation of the splprep function, it says that amongst the return values, there is also the variable "fp" that contains the residuals of the spline fit. http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.splprep.ht...
user1984653
1

votes
1

answer
60

Views

Inconsistent type of *args

I'm trying to write a generic memoization function in python 2.7 (no issue in 3.x) def init_memoize(): fns = dict() def memoize(fn, *args): if fn not in fns: fns[fn] = dict() print type(args) # prints "" print args in fns[fn] # throws the error if args not in fns[fn]: fns[fn][args] = fn(*args...
twinlakes
1

votes
1

answer
967

Views

Python xlsxwriter TypeError: tuple indices must be integers, not str

I am new to the xlsxwriter module and I am getting an error I cannot figure out. I am running the following code on a Ubuntu linux machine and Python version 2.7.3: import xlsxwriter import csv from csv import DictReader, DictWriter import sys import time csvfile = sys.argv[1] recFields = ['Recommen...
CircuitB0T
1

votes
2

answer
2.2k

Views

BeautifulSoup on multiple .html files

I'm trying to extract information between fixed tags with BeautifulSoup by using the model suggested here enter link description here I have a lot of .html files in my folder and I want to save results obtained with a BeautifulSoup script into another folder in the form of individual .txt files. Th...
user3635159
1

votes
2

answer
4.8k

Views

How to resolve “NameError: global name 'x' is not defined” error while running Robot Framework testcase using custom Library?

I am seeing "NameError: global name 'x' is not defined" error while running Testcase in Robot Framework. Following is my custom Library file (Modified as per Bryan Oakley comments): import re def pass_fail_criteria(): if int(re.findall(r"NUM_FLOWS\n-+[\s\S]*?(\d+)\s*-+",x)[0]): return "pass" else: r...
rcubefather
1

votes
3

answer
50

Views

How to use reduce in this case?

class Solution: def calculateMinimumHP(self, dlist): dlist is a list of lists. Sometimes dlist values is just like: [[1],[2],[3],[4]]..... the sub list only contains one item.I need to sum the whole list value. I can use for to add the value one by one OR I could use reduce()... I write as : reduce...
liuzhidong
1

votes
1

answer
3.4k

Views

Python SciPy IndexError: the length of bounds is not compatible with that of x0

I'm new to optimizations using Python and scipy. I'm getting the error IndexError: SLSQP Error: the length of bounds is not compatible with that of x0. when trying to pass the bounds parameter into scipy.optimize.minimize x0 = np.array([[2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2]]) bounds = ( [(...
Nyxynyx
-2

votes
1

answer
28

Views

Convert a table data into python tuple

I have below raw_data. ''' Filter_Port table type : filter_1 ports : [7d77a1b7-434b-47fd-b2aa-d3442b831205] type : filter_2 ports : [95a67e8c-63f9-4efc-b6b1-c04d5df61578, e1fea65f-62a3-43e9-8c33-c0e44ac3c86a] type : filter_2...
P De
1

votes
3

answer
1.7k

Views

Python read text file as binary?

I was trying to build an encryption program in python 2.7. It would read the binary from a file and then use a key to encrypt it. However, I quickly ran into a problem. Files like image files and executables read as hex values. However, text files do not using open(). Even if i run file=open("myfil...
user2514631
1

votes
4

answer
87

Views

Python function definition with function as optional argument

I would like to have a function as an optional argument of another function in python but it is not clear for me how I can do that. For example I define the following function: import os, time, datetime def f(t=datetime.datetime.now()): return t.timetuple() I have placed t=datetime.datetime.now() in...
pebox11
1

votes
3

answer
54

Views

What is this syntax in Python

if there is a syntax like this in python what exactly is it declaring defining? I tried looking in in the python website did not seen anything like this children = cell["CHILDREN"]
ajax_velu
1

votes
1

answer
3k

Views

How to find the Bit Depth of an image

I am trying to get the Statistics of image like width, height, bands, min, max, mean, stddev etc., I could find all of these but however i can't find the Bit Depth of an image. i could not find any function , is there a way for this ?
PythonLearner
1

votes
2

answer
5.3k

Views

xgboost watchlist parameter: DMatrix object is not iterable

I am trying to train a xgboost model on a dataset X-train, X_test. Code: xgb_params = { "objective": "multi:softmax", "eta": 0.3, "num_class": 62, "max_depth": 10, "nthread": 4, "eval_metric": "merror", "print.every.n": 1 #"silent": 1 } num_rounds = 2 mask = np.random.choice([False, True], len(X_tr...
sinhayash
0

votes
3

answer
35

Views

Comparing values of two dictionary's items

I need to compare the values of the items in two different dictionaries. Let's say that dictionary RawData has items that represent phone numbers and number names. Rawdata for example has items like: {'name': 'Customer Service', 'number': '123987546'} {'name': 'Switchboard', 'number': '48621364'} No...
Matrix166
1

votes
1

answer
2.3k

Views

order of inheritance in Python classes

I have a class ExampleSim which inherets from base class Physics: class Physics(object): arg1 = 'arg1' def physics_method: print 'physics_method' class ExampleSim(Physics): print 'example physics sim' Imagine these classes containing lots of code. Now i have made some modifications to Physics by def...
nluigi
1

votes
0

answer
48

Views

Distribute a list of elements into 3 lists with different exclusions

I have a list of ~100,000 unique IDs and I need to distribute them into 3 lists so that each list gets ~33,000 of them. The tricky part is that each of those lists has ~20k of the unique IDs that they can't use: an exclusion list. Those 3 exclusion lists overlap by 15%-50% and vary in size, but in...
Xodarap777
0

votes
0

answer
3

Views

Numerically solve nonlinear differential equation using RK4 in Python

I am attempting to solve the following nonlinear differential equation via RK4 method (in python): y' = a(b - v(y)) where v(y) = l(2αy + 4βy^3 + 6γy^5) and α,β,γ are given parameters. I am not given initial conditions so I plan to simply set y'(0) = 0 and y(0) = 0. Currently just trying to wr...
f987380
1

votes
1

answer
1.2k

Views

Formatting a table via SQL database in Flask

Having a slight HTML formatting issue with my Flask app. I'm trying to display a list of some data I have on court cases in a table, and the table has a heading of Full Name, Type of Appeal Filed, County. however, I can't figure out how to properly combine HTML syntax and Flask syntax in order to...
n1c9
1

votes
1

answer
1.9k

Views

Set a column in numpy array to zero

I want to set a column in numpy array to zero at different times, in other words, I have numpy array M with size 5000x500. When I enter shape command the result is (5000,500), I think 5000 are rows and 500 are columns shape(M) (5000,500) But the problem when I want to access one column like first c...
S.AMEEN
1

votes
1

answer
1.2k

Views

Update the global variable in Rospy

i have the problem. I have two node, node 1 and node2, where node1 send a float number in node2 and node2 send a float number in node1. In the function callback, I want sum the information received with other value and update the variable. But the problem is that i don't succeed the information sent...
crisannik

View additional questions