Category "python-2.7"

How to convert integer into date object python?

I am creating a module in python, in which I am receiving the date in integer format like 20120213, which signifies the 13th of Feb, 2012. Now, I want to conver

Serialize datetime.datetime object as JSON

Currently working on a quick little project in python and am attempting to encode an object into a JSON string. I've done this several times before without any

parse pcap file with scapy

I am comparing scapy and dpkt in terms of speed. I have a directory with pcap files which I parse and count the http requests in each file. Here's the scapy cod

(13: Permission denied) while connecting to upstream:[nginx]

I am working with configuring Django project with Nginx and Gunicorn. While I am accessing my port gunicorn mysite.wsgi:application --bind=127.0.0.1:8001 in Ng

Why does PyCharm give unresolved reference errors on some Numpy imports?

The following line in PyCharm is flagged by on-the-fly inspection with unresolved reference errors for each import. (They are underlined red.) from numpy impor

pm2 crash with too many unstable restarts (16). Stopped. "errored" in python

I have created a script that can run the python django application. I run this script using pm2. I do pm2 start scripts.sh, it works properly but after some tim

Why is print("text" + str(var1) + "more text" + str(var2)) described as "disapproved"?

Why is the code below termed 'age-old disapproved method' of printing in the comment by 'Snakes and Coffee' to Blender's post of Print multiple arguments in pyt

How to read data from a zipfile on a website without locally downloading zipfile

I am using the following piece of code: import zipfile import urllib link = "http://www.dummypage.com/dummyfile.zip" file_handle = urllib.urlopen(link) zip_fi

I am getting a syntax error while importing the zipfile module in python 2.7

python command in script: import zipfile Output on screen Chetans-MacBook-Pro:work chetankshetty$ python myprog.py Traceback (most recent call last): File

Python 2.7.12 zipfile password exception

I have a question to the zipfile library in python 2.7.12. It seems that if I try to extract a .zip that is password protected, an exception is thrown. I am ab

extract only the subfolder, not the whole folder

Is it possible to extract only a subfolder from an archive, rather than the whole folder? I.E. : I have my .zip/.tar.gz file named my_archive, which has inside

How to check the version of Python modules

I just installed the Python modules: construct and statlib with setuptools like this: # Install setuptools to be able to download the following sudo apt-get ins

Duplicated rows when merging dataframes in Python

I am currently merging two dataframes with an outer join. However, after merging, I see all the rows are duplicated even when the columns that I merged upon con

python regular expression - re.findall() in list

This is my list: lista=[u'REG_S_3_UMTS_0_0 (RNC)', u'REG_S_3_UMTS_0_1 (RNC)', u'REG_S_3_UMTS_0_2 (RNC)', u'REG_S_2_GSM_NORT_CBSP_bsc_0_0 (BSC)', u'REG_S_2_GSM_

Consolidating two scripts into one new one (appending columns to csv)

I have two scripts which create new columns within a csv, each of them opening the csv and appending a new column. Ideally rather than saving csv to csv1 then o

Searching in Google with Python

I want to search a text in Google using a python script and return the name, description and URL for each result. I'm currently using this code: from google im

Searching in Google with Python

I want to search a text in Google using a python script and return the name, description and URL for each result. I'm currently using this code: from google im

How to close the cmd window after the batch file run

I want to close the command prompt after the bat file run. From the bat file it's calling two python scripts and I have tried basic exit and many solutions to c

Apply a function to three parallel array of arrays

I have three arrays of arrays like this: catLabels = [catA, catB, catC] binaryLabels = [binA, binB, binC] trueLabels = [] trueLabels.extend(repeat(y_true_cat

>90% of the time is spent on method 'acquire' of 'thread.lock' objects

To identify the step that is using most of the computation time, I ran cProfile and got the following result: ncalls tottime percall cumtime percall fil