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,807
questions
0
votes
0
answers
14
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
33
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
18
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
11
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
35
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
0
answers
26
views
Reading book "Python for dummies" - and __main__message error
I'm reading Python for Dummies and the book says I should write this:
>>> class Message:
... pass
>>> Message
<class __main__.Message at 0x58db0>
>>> print Message
...
0
votes
1
answer
39
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 ...
-2
votes
0
answers
44
views
Multiprocessing in phython
Am reading an XML files with many XSLT using the below code to read the same .need to multiprocessor it such a way thread each XSLT runs in separate process or thread. Since am new to python am ...
2
votes
1
answer
40
views
Is there any difference between using a decorator and applying the function directly?
I recently became the maintainter of PyPDF2 - a library which is pretty old and still has some code that deals with Python versions before 2.4. While I want to drop support for 3.5 and older soon, I ...
0
votes
1
answer
38
views
How do I change python encoding to execute pvpython?
I am trying to execute pvpython (from ParaView) in Linux. The problem is that when I try to execute pvpython by typing
python2 -i $HOME/Downloads/ParaView-5.10/bin/pvpython
I get an error:
...
0
votes
0
answers
13
views
problem with addressing the working folder from within another software python shell [duplicate]
I have a python file that must be called from within a software (which use python 2.7). This python file use np.loadtxt() to read some data. The software have its own working directory, so when I want ...
0
votes
1
answer
50
views
Python2 to Python3 upgrades
PYTHON 3 EXAMPLE
>>> import six
>>> six.PY3
True
>>> import mock
>>> x = mock.MagicMock()
>>> y = min(x,2)
Traceback (most recent call last):
File "...
0
votes
0
answers
36
views
Google Foobar Challenge: "Prepare the Bunnies' Escape" - Dijkstra's Algorithm Implementation
I'm having a go at the Google Foobar Challenge, currently on the Prepare the Bunnies' Escape problem.
Problem definition:
You're awfully close to destroying the LAMBCHOP doomsday device and
freeing ...
0
votes
0
answers
204
views
ImportError Python cannot import name
I am trying to reproduce a code from a scientific publication which uses Python 2:
https://github.com/TeamErlich/dna-fountain
The code is based on Python 2 so I had to change my environment to Python ...
1
vote
0
answers
32
views
How do I add an if statement without breaking my code?
I am working with python zope printing html code and the traceback isn't very helpful. I want to add an if statement to check if "test(highlight_today == 'yes' and DateTime(container.util....
0
votes
0
answers
17
views
How to feed custom options/flags in curl using python urllib2 library
I have to upload an artifact to JFrog Artifactory using the cUrl request
sample:
curl -sSf -H "X-JFrog-Art-Api:<API_KEY>"
-X PUT
-T file.zip
'http(s)://<ARTIFACTORY_URL>///...
0
votes
1
answer
31
views
Python code opening json file - more optimal
How could I write this piece of code more optimal, not to have repetition? So, first I'm checking if there's a .json file, if there isn't I make it. If there is, I first open it, update it with new ...
2
votes
1
answer
216
views
how do I install python2 on centos 9 stream?
I am trying to figure out how to install python2 on centos9 stream. I am getting the errors below. Any suggestions?
sudo dnf install python2
Last metadata expiration check: 0:04:48 ago on Thu 24 Feb ...
0
votes
0
answers
25
views
./write_eeprom.sh: line 29: unexpected EOF while looking for matching `"'
Error: unexpected EOF while looking for matching `"'
Code:
#!/bin/bash
qr_heisys=$1
testpath='/home/home/Heisys/tester/app/dut/variant'
if [[ $testdesc == "-h" ]]
then
echo &...
0
votes
0
answers
25
views
Is there a way so that a statement doesn't run at the start of a program?
I am making an MS-DOS operating system in Python, and I want the user to select an application to run.
print("""
[1] Open notepad
[2] Open file explorer
[3] Configure BIOS
[4] Exit OS ...
0
votes
0
answers
169
views
How do I run an application for the Ryu SDN controller written in Python 2?
The work is carried out on the Ryu controller, the source code of which is posted here: https://github.com/faucetsdn/ryu/tree/master/ryu
In addition, the following software is used
1)!Ubuntu 20.04 LTS
...
0
votes
1
answer
65
views
GLib.Error: Required gtk+ version 3.20, current version is 3.18 (7)
I have an old program written in Python2 i need to use, but it's not getting along with Ubuntu Xenial's dependencies.
I had to manually fetch these in order to get it to run:
libwebp6_0.6.1-2ubuntu0....
0
votes
0
answers
49
views
ImportError: No module named PyQt5.QtWidgets after converting python2 to python3 and pyqt4 to pyqt5
I have a program that was written in python2 and PyQt4 that I want to upgrade/convert to python3 and PyQt5.
I have changed the code/syntax from python2 to 3, and fixed the imports from PyQt4 to PyQt5, ...
0
votes
0
answers
10
views
Green thread options for python2
At the moment we cannot upgrade to py3, but we need to implement virtual threads to enable parallel DB calls. What options do I have? Are there libraries or am I left with writing my own ...
-1
votes
1
answer
172
views
How to install Tensorflow==1.X.X for Python2.7 on Ubuntu?
I try to install tensorflow==1.1.0 for Python2.7 with pip package manager but am getting the following error when I run the command pip install tensorflow:
DEPRECATION: Python 2.7 reached the end of ...
1
vote
0
answers
43
views
Why PYTHONPATH is shared between python2.x and python3.x
I have a simple question that really bothers me. Say, I am using python2 and python3 (depends on the project and situation, sometimes leftover codes etc.). I also don't like to use virtual ...
-1
votes
1
answer
28
views
Python3 equivalent to Python2 open when encountering UnicodeDecodeErrors [duplicate]
I had a script I was trying to port from python2 to python3.
I did read through the porting documentation, https://docs.python.org/3/howto/pyporting.html.
My original python2 script used open('...
0
votes
1
answer
28
views
Import of python package `pyunpack` throws invalid syntax error
I'm using python 2.7 and pip 20.0.2 and have intalled paramiko pyunpack patool tqdm packages in my virtual env.
But the below line throws a syntax error. Why would that be?
from pyunpack import ...
2
votes
2
answers
224
views
In Kali Linux, why do I only see python2 and python3 binaries (NOT a 'python' binary) in /usr/bin/ and get "python command not found"
I am running latest version of Kali Linux:
uname -a
Linux User 5.14.0-kali4-amd64 #1 SMP Debian 5.14.16-1kali1 (2021-11-05) x86_64 GNU/Linux
It already came with Python 3.9....
2
votes
3
answers
73
views
Two versions of python giving two different results for the same code
The following code produces two different results if run using Python2 or Python3. Why?
from skyfield.api import wgs84, load
latitude = -35
longitude = 150
altitude = 100
year = 2022
month = 1
...
-2
votes
2
answers
58
views
Calculating the recursive "n" number
I am teaching my self python 2 at the moment using exercise books. I am currently studying recursive function. I am a bit confused how the "n" value is calculated. Below as a simple example ...
1
vote
1
answer
116
views
Testing the same function with different parameters
I am trying to test a function multiple times using different parameters. The return value should be True.
def testConfiguration(small,medium,large):
...
if (everything goes well):
...
0
votes
1
answer
267
views
How can I resize terminal window from Python?
I'm trying so hard and pushing myself to my limits, but I just can't figure out how to resize a terminal to my desire. Is there any way that someone can help me solve it? I would like the terminal ...
-1
votes
1
answer
69
views
Installing pip in Raspberry pi3
Sorry I am newbie, when I try to install pip using following command
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
I get following error
ERROR: This script does not work on ...
0
votes
1
answer
46
views
Don't understand why Map returns iterator makes code to fail
I have some code that does:
map(lambda increment:
self.__delete_table_id_range(table, delete_field, value,
delete_interval, increment),
...
0
votes
1
answer
349
views
Constructing Bech32 addresses
I'm trying to follow the steps here https://en.bitcoin.it/wiki/Bech32 to generate a valid bech32 address. I am getting stuck on the first step:
Having a compressed public key (0x02 or 0x03 followed ...
0
votes
1
answer
34
views
In Python 2 do we need a self keyword for a function even if the function isn't part of a class?
So I'm looking through some old python 2 code and I see this function
def manage_addMapSamlPlugin(self, id, title='', delegate_path='', REQUEST=None):
""" Factory method to ...
-1
votes
1
answer
76
views
Do Python 2 and 3 share the same set of magic methods?
Do Python 2 and 3 share all the same magic methods (with their names being exactly the same)?
If not, does anyone know of a handy comprehensive list of all the magic methods in Python 3?
0
votes
0
answers
6
views
How do I do circular imports in python2 packages?
I've boiled down the issue to the following...
In subdirectory test/ I have three files: foo.py, bar.py, And an empty __init__.py
foo.py:
from . import foo as f
x = 20
def bar(z) :
global x
x = ...
1
vote
1
answer
85
views
Python 2 Syntax error when executing print in boolean expression
In order to demonstrate that python performs short-circuiting I tried to run the following code snipplet
True or print('here')
and expected the code to execute, evaluate to True and not print "...
0
votes
0
answers
70
views
/usr/bin/python: No module named pip when using pip with python2
I am following the installation guide for the Tensorflow Object Detection API, which determines the following:
//From within TensorFlow/models/research/ cp object_detection/packages/tf2/setup.py . ...
-1
votes
1
answer
53
views
Get the element of list or index of list while "for" looping with step in range
I am looping through a list with step as below:
list_of_names = ["james", "jack", "jill"]
for i in range(1, len(list_of_names) * 6 + 1, 7):
print(i, i + 6)
Now I ...
0
votes
0
answers
44
views
QXcbConnection: Could not connect to display, when calling gui tool by os.system
In my pyqt code I am using subprocess.Popen command to source csh file with env variables. It works properly. But after that when I am using os.system command to call linux gui tool (ex. nedit, etc...)...
0
votes
1
answer
41
views
How to set python source code encoding with swig
When I wraps a library with swig
swig -python my_ext.i
This generate a my_ext.py file.
How to add file encoding in the first line, when creating my extension with distutils.extension.Extension ?
# -*-...
0
votes
1
answer
443
views
how can i import Document in python module docx?
Hi I'm using mac and installing python-docx using pip. I went into C:\Python27\Scripts and ran
pip install python-docx
I thought it should have been installed.
But when i run a simple import
from ...
0
votes
0
answers
8
views
How to get past input prompts of binaries using subprocess?
I have been trying to find a way to get past prompts on specific commands/ binaries that don't allow flags for specific things, I've been trying to use expect and read commands using bash however it ...
0
votes
0
answers
36
views
How can I convert lambda from Python2 to Python3? [duplicate]
Now I am rewriting Python2 scripts to Python3 scripts.
In the Python2 script, the code below was successfully launched.
But in the Python3 script, it had an syntax error.
If somebody knows why it ...
0
votes
2
answers
133
views
Text between tag using SAX parser in Python
I want to print the text between a particular tag in an XML file using SAX.
However, some of the text output consist of spaces or a newline character.
Is there a way to just pick out the actual ...
0
votes
0
answers
28
views
How can I convert Python 2.7+ code using format with zero length field name to 2.6 style named fields?
I'm trying to use this code which uses zero length field names with format, e.g.,
return '{} is initialized'.format(self.value.type_name)
I am stuck using Python 2.6, which doesn't support this:
...
0
votes
0
answers
36
views
encoding jsonl file as utf-8 failing in Python 2.7
I am currently working with Python 2.7.7 and I am trying to read in a jsonl file from standard input via the console:
python my_single_jsonl.jsonl | my_python_code.py
This is the code I am using to ...