Questions tagged [python-2.7]

32976 questions
1

votes
1

answer
1.6k

Views

Python- How to make an if statement between x and y? [duplicate]

This question already has an answer here: How do I check whether an int is between the two numbers? 7 answers I've recently been breaching out to Python, as C++ is fun and all, but python seems kinda cool. I want to make Python do something as long as the input is between a certain number range....
Nate Dukes
1

votes
2

answer
1.2k

Views

Hamming Window, python 2.7

Hi I have a FFT which is quite noisy. How to apply to my code Hamming window to make it less noisy. Look at my code: plt.subplot(212) plt.title('Fast Fourier Transform') plt.ylabel('Power [a.u.]') plt.xlabel('Frequency Hz') fft1 = (Bx[51:-14]) fft2 = (By[1:-14]) for dataset in [fft1]: dataset = np.a...
Hiddenguy
1

votes
5

answer
1.2k

Views

Python add one more channel to image

I'm trying to add channel because of below error ValueError: could not broadcast input array from shape (48,48) into shape (48,48,1) Code: img = cv2.imread(f,0) resized = cv2.resize(img, (48,48), interpolation = cv2.INTER_AREA) print(resized.shape) (48, 48) But I need a channel image like (48,48,1...
Hasan Ramazan
1

votes
3

answer
66

Views

Python regular expression to split parameterized text file

I'm trying to split a file that contains 'string = float' format repeatedly. Below is how the file looks like. +name1 = 32 name2= 4 +name3 = 2 name4 = 5 +name5 = 2e+23 ... And I want them to put it a dictionary. Like... a={name1:32, name2:4, name3:2, name4:5, name5:2e+23} I'm new to regu...
윤제균
1

votes
1

answer
413

Views

How to find the number of upstream tasks failed in Airflow?

I am having a tough time in figuring out how to find the failed task for the same dag run running twice on same day(same execution day). Consider an example when a dag with dag_id=1 has failed on the first run (due to any reason lets say connection timeout maybe) and task got failed. TaskInstance t...
mad_
1

votes
1

answer
2.5k

Views

Create a dockerfile that runs a python http server to display an html file

I have a directory with one simple HTML file (name: index.html) which displays some basic text. I run the python command: python -m SimpleHTTPServer 7000 to run a server, at port 7000, in the same directory to display the page in a browser. Now I want to be able to dockerize this process and need...
El Tikki
1

votes
1

answer
37

Views

create dataframe in python from list

I have extracted multiple data from file and now I want to create the dataframe of my data of interest. I have tried following way: anticodon = re.findall(r'(at.\w\w-\w\w)', line) for line in anticodon: anticod = line.replace('at ', '') import pandas as pd df1 = pd.DataFrame({'id': [m_id], 'cod': [a...
Kritika Rajain
1

votes
2

answer
255

Views

Paramiko scp copy from remote machine regular expression

Is there way i can copy remote files that ends with name 'output' using paramiko scp. I have below code, which copies only if i provide full path or exact file name Below is code import paramiko import os from paramiko import SSHClient from scp import SCPClient def createSSHClient(self, server): cli...
Dev Ops Ranga
1

votes
1

answer
1.1k

Views

django.core.exceptions.SuspiciousFileOperation: The joined path is located outside of the base path component

This worked fine everytime used to do django websites but this time it is giving me an error. Settings.py STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'portfolio/static/') ] STATIC_ROOT = os.path.join(BASE_DIR , 'static') STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL...
Kiran Chavan
1

votes
3

answer
94

Views

A SWIG multi-argument typemap apply to functions, but not to the constructor if there's multiple constructors

I'm trying to make a quarter float type in C++ and wrap it to Python using SWIG. This is a work in progress. The problem is %typemap(in) (int dim_count, int* shape) does not apply to the constructor if there's more than one constructor. If I use just a one constructor it looks like this: Python 2.7....
1

votes
2

answer
19

Views

How to determine if an argument to a function is different from the last invocation

I have a function x taking one parameter y. Inside x, I want to determine if y is the same or different from the previous call to x (actually it is only part of y I care about, but the splitting details are not relevant). Currently, I use a global last_y initialized with an impossible y value and ch...
Steven Deller
0

votes
1

answer
6

Views

'curl' is not recognized as an internal or external command, operable program or batch file

While executing curl command through os.system(cmd) in python script cmd='curl' os.system(cmd) 'curl' is not recognized as an internal or external command, operable program or batch file.
Rishabh Jaiswal
1

votes
2

answer
50

Views

Create a list of dictionaries with unique keys from a list of dictionaries with duplicated keys

I have a list of dictionaries: records = [{id:123, name:'Course A', enrolled_date:'1st Feb'}, {id:123, name:'Course A', enrolled_date:'1st Jan'}, {id:456, name:'Course B', enrolled_date:'1st Jan'}] I want to create a new list of dictionaries from this data. The new list should only contain diction...
Zak Smith-Sanga
1

votes
4

answer
60

Views

How to create a dictionary to reverse lookup list items that each have sets?

I have test names in a list like this in Python v2.7: all_tests = ['test1', 'test2', 'test3', ..., 'testN'] And for each test name, I can lookup a set of properties that the test has: series['test'] = {'prop1', 'prop2', 'prop3', ..., 'propN'} E.g., series['test1'] = {'yellow', 'blue', 'orange'} seri...
WilliamKF
1

votes
2

answer
40

Views

Get a key: value pair dictionary from two consecutive columns of pandas dataframe

I am extracting data from excel sheet and storing it into a dataframe. I want to create a key:value pair dictionary from the columns of dataframe. For example: [{key=column1 : value = column2, key = column3 : value=column4 }], and so on till the last column. Here is the sample data on which I am wor...
Priyanka Lanjewar
1

votes
1

answer
33

Views

I tried to send an SMS using Twilio in Python 2

I wrote a code in Python 2 to send an sms, but I got an error. from Twilio.rest import Client # Your Account SID from twilio.com/console account_sid = 'secret' # Your Auth Token from twilio.com/console auth_token = 'secret' client = Client(account_sid, auth_token) message = client.messages.create(...
waseem hazem
1

votes
3

answer
43

Views

How to use For Loop to add integer as a string in list?

I have created the list below: Stores = ['Costco','Publix', 'Kroger', 'Target'] I am asked to create a another list (Store_Rank) to define their ranking by adding integers in front. However, the integers should be in a list format. I am assuming f-interpolation is to be used? 'Store_Rank' list shoul...
Kadodo14
1

votes
2

answer
46

Views

Is there a way to send log.html,report.html and output.xml in email after test completion in robot-framework?

I am trying to achieve one scenario in which i need to send log.html, report.html and output.xml directly in the email after completion of test suite and test case. I saw discussions on this part but not able to get the proper answer. My questions are: How we are able to achieve this task if its pos...
Chirag Dhingra
1

votes
1

answer
23

Views

Different behavior of generators in python-2.7.12 and python-3.5.2

Generators behave differently in python2 and python3 for the code below. def g1(): for i in range(3): print('in g1: {}'.format(i)) yield i def g2(): for i in range(3): print('in g2: {}'.format(i)) yield 2*i def g3(f1,f2): for (i,(x,y)) in enumerate(zip(f1,f2)): print('in g3: {} ---- {},{}'.format(i,...
Abhijeet Awasthi
1

votes
1

answer
18

Views

Unable to generate correct hash table for columns in CSV file

I have a CSV file with the following columns, ZoneMaterialName1,ZoneThickness1 Copper,2.5 Copper,2.5 Aluminium,3 Zinc, Zinc, Zinc,6 Aluminium,4 As can be seen, some values are repeating multiple times, and can occasionally be blank or a period. I would like a hash table with unique values only, lik...
Chetan Yadav
1

votes
1

answer
52

Views

Why [] is [] gives False in Python [duplicate]

This question already has an answer here: Why does “[] is [ ]” evaluate to False in python 4 answers I'm bit confused with this logic. When the following gives True in python print('' is '') #True print('' == '') #True print([] == []) #True print({} == {}) #True But why these statement give...
Vanjith
0

votes
0

answer
17

Views

Loop takes too long to replace values

I have a 9 mln line of code where I have to replace every ' . ' with the number in the line above. Meaning that if column 1 contains ' 7 ', the dot below should be replaced by that. But if column 3 contains ' 44 ', the subsequent values have to be replaced by 44 and so on. Problem: at the the moment...
Patrick Lombardo
0

votes
0

answer
6

Views

Python - Django 1.5 Is there a possible workaround to fix database error

Im working a school management project and I integrated a forum app. It now pushes a database error even after I migrated / synced the database. Are there possible workarounds? Request Method: GET Request URL: http://127.0.0.1:8000/admin/forums/category/add/ Django Version: 1.5.12 Excepti...
Dre James
0

votes
0

answer
4

Views

How do I Combine/Merge PDFs with Fillable Form Fields using pyPDF2, Python?

Fields in PDFs have an Unusual Property: All fields with the same name are the same field. They share value while merging the pdf.
sabin shrestha
0

votes
0

answer
5

Views

Alexa Skill Proactive Events Python Implementation

I was wondering if someone can help me point in the right direction to implement Proactive Events to my already existing Alexa Skill. My Code is running on AWS Lambda on python. If someone can help me with a general example of implementation, that would be great. Needs to be in Python. Thank you!
charsi
1

votes
3

answer
3k

Views

how to parse a boolean argument in a script?

The following function and usage examples illustrate exactly what I need with this usage: test([{True | False}]): >>> def test(arg=True): ... if arg: ... print 'argument is true' ... else: ... print 'argument is false' ... >>> test() argument is true >>> test(True) argument i...
Joel Daroussin
0

votes
2

answer
29

Views

How to make multiple calls using the Twitter API in Python

I am doing a historical search of Twitter data using Twitter's Sandbox API. I am using the TwitterAPI package on Python. Sandbox allows a total of 50 requests of the API per month. I have this code below, which is collecting the data fine, but has only conducted one request, meaning I only have 100...
SimonCopland
-1

votes
1

answer
14

Views

How can I delete the feature within a feature class with the largest area using cursor and arcpy?

I am trying to delete the feature within a polygon shapefile that has the largest area. I have a column in the attribute table with the areas, and can generate a variable with the max area. But I am not able to pass this variable into a loop to delete the feature using cursor. When I insert the act...
chickadee1310
1

votes
0

answer
12

Views

Client program only connecting to server 1/2 of the time. Python noob, can't figure out why

I'm attempting to set up a client program that interacts with 3 different servers, AS, TS1, and TS2. I boot up the servers TS1, TS2, and AS and then I start Client, however on first attempt my client gives me '[Errno 61] Connection refused'. This shuts down TS2, AS, and Client obviously. TS1 remains...
Jessi Medina
1

votes
1

answer
492

Views

Multiple language datetime text to standard date format [closed]

I'm using dateutil.parser.parse in Python to standardize dates. Not all of the dates are in English. Therefore, the standardization process failed with 'unknown string format' error. Is there a way to process such dates or at least avoid the error? Sample date formats: Wed, 17 Oct 2001 11:49:53 -070...
Naveen Mathew
1

votes
2

answer
480

Views

Python Kivy: unable to import main main

While reading the book, Creating Kivy apps with Python, it says to 'Next, update the imports in weather.kv to import this main module instead of the ListItemButton class; see Example 3-7. Example 3-7. Importing a custom class from main #: import main main #: import ListAdapter kivy.adapters.listadap...
John Doe
1

votes
1

answer
5k

Views

Axes3D: Numpy arrays error while trying to build 3D plot

Let's start from the beginning. This how I getting x and y values: from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection='3d') # get current axis w0 = np.arange(30, 80, 1) # x - values w1 = np.arange(-3, 3, 0.1) # y - values X, Y = np.meshgrid(w0, w1) # no idea why to do...
Rocketq
1

votes
3

answer
1.4k

Views

PyTest: test which function was called in the if statement

I have a function, which considers three different cases and for each case calls a different function, like in the example below def my_fun(input): if input == 1: fun1() if input == 2: fun2() if input == 3: fun3() I would like to write a test for function my_fun using py.test, but I don't know how I...
Ziva
1

votes
4

answer
2.8k

Views

speech_recognition module stuck in “say something” - python

I am trying a python script for speech recognition, i have installed the required pyaudio and SpeechRecognition modules in my enivronment. The program was running fine till yesterday, but now it is stuck in 'say something'. Below is my code. import speech_recognition as sr print 'say something1' r =...
Sleez
1

votes
2

answer
1.8k

Views

How to extract labels from a Binary Image in SimpleITK in python

I would like to extract the labels from the 2D Binary image I get using the following code: image2DThresh = sitk.Threshold(image2D, lower=stats.GetMinimum(), upper=127.500) cca = sitk.ConnectedComponentImageFilter() cca_image = cca.Execute(2D_Slice) # Get the shape statistics of the labels using lab...
Rick M.
1

votes
2

answer
338

Views

How to retain precision when converting from float32 to float?

I have a numpy.float32 object that I want to encode as JSON. The problem is that when I convert to a native python float, I lose the precision of the value. Example: In [1]: import numpy as np In [4]: np.float32(295.96).item() Out[4]: 295.9599914550781 However, if I first convert to string, then to...
FGreg
0

votes
3

answer
15

Views

(python) how to get all the values by keys that is in range

I have a dictionary like : dict = {8.12: 4, 6.93: 2, 6.78: 2, 7.04: 2, 7.21: 2, 8.05: 4, 7.48: 2, 6.52: 0, 6.95: 2, 7.28: 2, 7.56: 2, 6.67: 0, 6.33: 2, 6.37: 1, 7.15: 1, 8.16: 5, 7.84: 3, 7.13: 2, 6.24: 0, 7.11: 3} I want to get all the values by key that is in range +- 1. For example, how can I g...
user11398251
1

votes
3

answer
808

Views

How to take multiple multiline input variables in Python?

Is it possible to take multiple newline inputs into multiple variables & declare them as int all at once? To explain further what I am trying to accomplish, I know this is how we take space separated input using map: >>> a, b = map(int, input().split()) 3 5 >>> a 3 >>> b 5 Is there an equivalent for...
deppfx
1

votes
1

answer
2k

Views

Python: Delete Objects and Free Up Space

Python documentation said that an object is considered deleted if the reference counts to the object is zero and the difference between del and __del__ is that: del reduces the reference count to an object by one __del__ executes when the reference count to an object is zero That means if we keep de...
Daozui
1

votes
2

answer
2.3k

Views

Pip Install Timeout Issue

I am trying to install pandas in my company computer. I tried to do pip install pandas but operation retries and then timesout. then I downloaded the package: pandas-0.22.0-cp27-cp27m-win_amd64.whl and install: pip install pandas-0.22.0-cp27-cp27m-win_amd64 But I get the following error: Retrying (...
Adhil

View additional questions