Questions tagged [python-2.x]
For questions about Python programming that are specific to version 2.x of the language. Use the more generic [python] tag for all Python questions, and only add this tag if your question is version-specific.
2,848
questions
1
vote
0
answers
25
views
Error: must be str, not int when passing input to strptime [duplicate]
I have an issue with my Python code which works on Windows XP (Python 2.7):
from datetime import datetime
from datetime import date
def temps_valide(nbrjmax):
try:
datetime.strptime(...
1
vote
5
answers
74
views
Python convert different depth list of tuples to flatten list of tuples [duplicate]
I have a tuple of characters like such:
p= [((4.0, 4.0), '->', ((4, 2), (4, 8)), ((2, 2), (5, 5))), ((4.0, 7.0), '->', ((4, 2), (4, 8)), ((5, 6), (3, 8)))]`
How do I convert it to a tupple so ...
0
votes
0
answers
36
views
How do I fix code that calculates the amount of combinations in the partitions of a set?
I am working on a code in Python 2 that partitions a set of 13 elements using integer partitions, then evaluating the different combinations they can have (order does not matter). I have seen the ways ...
0
votes
2
answers
40
views
issue about pexpect logfile_read
use pexpect SSH connections to run cmds on remote server, the command can be executed, but the results displayed on the terminal are not as expected, code like this(At first there was no time.sleep, ...
0
votes
2
answers
110
views
How to reverse byte order the elegant way? (from big-endian to little-endian) [duplicate]
Hi all my internet friends!
This is the method I am using right now, not very elegant and not very useful if the hex value gets bigger:
"compressed_filled_01" is an hex value, 0x00024680
###...
0
votes
0
answers
27
views
Can't install pyenchant
I need installing pyenchant v1.6.7 on MacBook with Apple Silicon (M1 Pro) for Python 2.7.18.
This package is a wrapper for C-library enchant, so it requires to the enchant was installed firstly. Well, ...
0
votes
0
answers
47
views
How import _pjsua in python
I tried to build the python module pjsua-2.9 by using pjproject-2.9 and then running setup.py build and setup.py install. I have the
packages pjsua-2.9-2.el8.x86_64.rpm, pjproject-2.9-2.el8.x86_64.rpm,...
0
votes
0
answers
98
views
SciKits.umfpack installation
I am trying to install on UBuntu 20.4 the scikits.umfpack python package because it is needed as a dependency for this python packages for network analysis on my dissertation.
I am also using python 2....
0
votes
0
answers
18
views
Pyneurgen package "print error" in python
I am trying to import the NARX model from the package pyneurgen in python, but when I try to execute
from pyneurgen.recurrent import NARXRecurrent
the error message
Traceback (most recent call last):
...
0
votes
0
answers
23
views
Assign stdout and stderr to a variable when sending output to a file with Subprocess in Python 2
# logging output and errors to file instead of PIPE
# as when the output is over 64K the process can hang for a long time
stdout_file = os.path.join("/var/log/", "migrate_stdout.log&...
1
vote
2
answers
79
views
Named tuples existence in a hashset
In [1]: x = set()
In [2]: pos = collections.namedtuple('Position', ['x','y'])
In [4]: x.add(pos(1,1))
In [5]: x
Out[5]: {Position(x=1, y=1)}
In [6]: pos(1,1) in x
Out[6]: True
In [8]: pos(1,2) in x
...
0
votes
2
answers
18
views
* operation in python for 2-d matrix initialization
You init a 2-d matrix like this
board = [[0] * width for _ in range(height)]
Instead of
board = [[0] * width] * height
as it creates the list once and every row references the same list.
Is it not ...
0
votes
1
answer
66
views
convert PSUTIL Process output to object/dict?
I am currently running the following script to get the system_md status of each host. Its working but the output I am getting is a Process Class and I am not sure how to parse the following params to ...
0
votes
1
answer
130
views
How To Run Nested Async Functions In Python?
Can anyone help me figure out how to run MethodTwo() asynchronously with the rest of the program?
Here is the code:
import asyncio
from asgiref.sync import sync_to_async
def MethodTwo():
print(&...
0
votes
2
answers
82
views
Python datetime not correct with regards to timezones when running in docker
I have a python 2.7 codebase that I'm trying to containerize. Much as I'd like to, our devs cannot move to Python 3.
When running natively in their dev environments, datetimes respect timezones. I can ...
0
votes
0
answers
24
views
Python script doesn't return anything
I am trying to run the below script to find a file starting with string file and ends with .txt and in the specified path.
When run, it doesnt return anything or errors out.
Please suggest on what am ...
0
votes
1
answer
20
views
How to run {gunicorn | or any python program} as python3
When I run gunicorn, python2 is always executed.
gunicorn -c gunicorn_config.py app:app
...
ps -ef | grep gunicorn
user 34877 1 0 16:31 ? 00:00:00 /usr/bin/python2 /usr/bin/gunicorn ...
0
votes
1
answer
88
views
Building python3 with ROS using vison_opencv: Raise CvBridgeError, "encoding specified as %s but image has incompatible type %s" % (encoding,cv_type)
I am trying to run python3 with ROS. By default ROS melodic is installed with python2.7.
Hence I have installed the python3 using following instructions:
https://dkqhzm2.tistory.com/entry/ImportError-...
0
votes
1
answer
44
views
Convert one column csv into Dictionary with same key:value pair in python 2.7 (using import csv)
I have one CSV file as sample.csv which contains
ABC
XYZ
LMN
...
And from this file, I have to make a dictionary like below
Dict = {'ABC':'ABC','XYZ':'XYZ','LMN':'LMN',...}
using import csv
0
votes
1
answer
54
views
Python2: Get longest Common Prefix path
I am trying to get last matching common path among list of paths below:-
"Linux-aarch64/gcc-7.3.0/aarch64-unknown-linux-gnu/include/c++/7.3.0/aarch64-unknown-linux-gnu/bits/"
"Linux-...
-4
votes
1
answer
30
views
PYTHON2: how to use a while loop and user input to count to a certain number that the user inputs?
So i have this code sprint assignment for school where i have the user input a certain number and then the computer program will count to that number. but i have no idea how to do thatenter image ...
-1
votes
1
answer
208
views
How to handle incoming "b'xxx'" string [duplicate]
I got below info from other device:
foo = { "abc": "b'E3:DE'" }
I know "b" prefix means byte in Python 3. My intent is to convert it into a string. My Python version ...
0
votes
0
answers
54
views
Python Django imported settings are not visible to other imported files
I have an old project with Python 2.7 and Django 1.6. I am trying to run it on Windows. My file structure:
myproj/
|-- myproj/
| |-- __init__.py
| |-- manage.py
| |-- ...
0
votes
0
answers
24
views
Why do I keep receiving a syntax error when trying to run pip install esptool onto my ESP8266?
I am trying to code my Feather Huzzah ESP8266 with Python. I have followed multiple different tutorials but have ran into the same error each time while trying to flash the device using esptool. The ...
0
votes
1
answer
35
views
How to build a HTML object in python3?
It used to be easy to build an HTML instance. In python 2:
import html
obj = html.HTML('html')
But in python3, there is no attribute as "HTML" under "html" module.
And I am ...
0
votes
0
answers
34
views
npm install of creative tim's vueJS template failing
I'm trying out a template created by creative Tim and have problems using npm install. However, upon installation, I am facing an error where it states that python2 cannot be found.
So this is what my ...
0
votes
1
answer
177
views
‘module’ object has no attribute ‘MStatus' in Maya python Api 2020
I am trying to build a command in python for Maya following a course on youtube and it's showing this error "# Error: RuntimeError: file line 2: AttributeError: file C:/Users/saeed/OneDrive/...
1
vote
1
answer
234
views
Calculate sum of columns of same name pandas
How can i search for duplicate columns in a dataframe and then create a new column with same name. the new column is result of 'OR' operator of these columns. Then drop old duplicated columns.
Example:...
0
votes
0
answers
35
views
python 2 - cookie and headers with urllib2
With python 2 :
I have 2 different problems.
With an url, I have this error:
urllib2.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
So I am ...
0
votes
0
answers
21
views
Things to update manually after python 2 to python 3 migration using an automated tool
I have been trying to migrate an older project which is mainly python 2.7 compatible to python 3.9. I did go through couple of python migration documentation and I have decided to use 2to3 tool for ...
0
votes
0
answers
30
views
How to load xlsb excel file into pandas dataframe in python 2.7
How to load xlsb excel file into pandas dataframe in python 2.7
and a.xlsb file has sheet 1.xlsb how to access the sheet which is a.xlsb file
0
votes
2
answers
91
views
Convert lists into dicts and access dict fields with dot-notation
Using python 2.7 (requirement coming from other factors):
Given I have
x1=["John", "Doe"]
x2=["Jane", "Dan"]
x=[x1, x2]
I need to have some function convert ...
1
vote
1
answer
37
views
Python 3 2-D list initialization breaks in Python 2
I'm trying to initialize a 2-D list using list comprehensions, but I'm seeing different results in Python 2 vs. Python 3 and I have no idea why. Sample code (the import is just so I can use v3 print ...
0
votes
1
answer
74
views
Using Python version 2.7 *virtually* when I only have version 3.10 installed
I have version 3.10.2 of Python installed on my Windows machine via the Anaconda distribution. There is an API that I'd like to use that supports only Python version 2.7.
In order to use this API, do ...
2
votes
1
answer
922
views
How to migrate from OOB OAuth?
I am running a python script on the device with no screen/no browser (ssh access only). The script used offline Google's OAuth:
def get_authenticated_service( self , args):
flow = ...
0
votes
0
answers
231
views
Can't import pyserial (ImportError No module named pyserial)
I have a script that currently requires Python2 to run. I have a fresh Ubuntu install setup by my IT this morning.
I get this error message when attempting the script: "ImportError: No module ...
0
votes
0
answers
149
views
i'm trying a twitch viewer bot for testing on my own channel and my code is not working
guys this is the error code i don't know what to do
File "threads_viewer.py", line 56
print(f"URL : {url[:30]}...\n")
^ SyntaxError: invalid syntax
...
0
votes
0
answers
67
views
EOF error with raw_input - Issue executing Python script from a reverse shell
I am currently helping my university's cyber security program by creating a simple Capture the Flag style python script to be used for the final exam. I created the script and everything is working ...
-2
votes
1
answer
319
views
when running my coder in terminal of vscode it says my variable is undefined
I wrote a simple piece of code in VScode but when I run it in the terminal an error pops up saying the variable is not defined. however when I manually press the run code button the code runs without ...
0
votes
2
answers
91
views
Trying to make a cookie clicker style game with Tkinter but Label won't change number [duplicate]
This is my code for a simple Tkinter project:
from Tkinter import *
root = Tk()
global cookie_count
cookie_count = "0"
cookies = Label(root, text=cookie_count)
cookies.grid(row=0, column=0,...
0
votes
1
answer
228
views
Install wxpython inside docker using python2
As a way to explore an old app, I'm trying to install wxPython inside Docker and I'm always getting an error when installing this package:
#6 297.0 Installing collected packages: pillow, six, numpy, ...
1
vote
0
answers
377
views
How do I resolve python print error when running npm install --force
trying to run npm install --force on my ubuntu server
get the following error:
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` ...
0
votes
2
answers
38
views
How to print lines from file if lines are given in list?
I'm fairly new to python (using 2.7) so I realize this might be an obvious solution. I'm writing this more to work through the issue on "paper" so to speak.
I have a file containing several ...
0
votes
1
answer
627
views
Openstack CLI client gives an error: ImportError: No module named queue
Openstack uses python 2.7 and not 3.x. In some cases, pip install python-openstackclient, would install a broken openstack client. Hence openstack client would not work. It would give following error: ...
0
votes
0
answers
51
views
how to run spiders in script with it's name ( Scrapy 0.24.1 and Python 2.7.10 )
I'm using Scrapy 0.24.1 and Python 2.7.10 in my project. I have some spiders with custom settings. my crawler works fine with the command line and the command is like this:
scrapy crawl sample_spider -...
0
votes
0
answers
79
views
Why use devnull with subprocess.check_output in python2?
I have inherited a complicated (to me) toolbox from a PhD student before me and it uses python2 instead of 3 since it's older. The main file is in python2 and uses lots of modules and user-made ...
0
votes
1
answer
150
views
add number from Json to SQL table in PowerAutomate desktop
I'm trying to get data from accounting software per Api by PoweAutomate desktop.
I get Json object and convert it to custom object.
Then I assign every atribute to a variable for adding it in sql ...
0
votes
0
answers
61
views
Python 2to3 command window conversion
I have some long scripts to convert from py2 to py3. Also, I am a beginner and I don't have experience with python.
On my computer (windows 10) I have python 27 and python 39.
I didn't understand how ...
0
votes
1
answer
523
views
How do I activate Python 2.7 in virtual environment in my Mac Terminal [duplicate]
I am trying to create a virtual environment on my Mac using terminal commands for Python 2.7 but it is not working.
I issue the following commands;
mkdir Environments
cd Environments
python -m ...
-1
votes
1
answer
376
views
For loop - I can only enter 1 integer
I am unable to enter more than one integer. I should be able to specify how many and then input like so...
How many integers? 3
Please enter an integer 1: 5
Please enter an integer 2: 2
Please enter ...