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,870
questions
0
votes
1
answer
36
views
How to save the output as csv file in python
I use this Python snippet to obtain the rabbitmq queue size output, which is already in csv format, however I would need to know how to save this data to a file.
import subprocess
proc = subprocess....
7
votes
3
answers
210
views
Separate lru for each argument value?
I need to write a sql database column getter, that takes in a column name and time, and returns the entire column of values for that column corresponding to the input time. This may be a frequent ...
0
votes
0
answers
33
views
"_func" not being imported even when declared in __all__
I am using Python 2.
I was able to find that __all__ by default does not pass _functions (underscored "internal" functions) when __all__ is not declared (i.e. just using from module import * ...
0
votes
2
answers
77
views
Dependent classes in Python
EDIT: After the discussion in the comments, this is the technical part of the question. There is also the aesthetic side, how to do this neatly.
How can I create classes that depend on parameters, but ...
0
votes
0
answers
19
views
Red Hat 7, Ansible and Multiple Python Installations
I have been issued a Red Hat 7 instance with Python2.7 installed and ansible.
I am looking to use Python3.8 and Ansible. I've installed Python3.8, and I've python3.8 -m pip install ansible
I have set ...
0
votes
0
answers
52
views
How to install pip for python2 and pip3 for python3 in Ubuntu Docker?
How can I install pip for python2 and pip3 for python3. So that when I run pip --version it should show pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7) and when I run pip3 --version, ...
-4
votes
1
answer
168
views
Understanding code for pricing Asian Option
I am looking at the code here for Asian option pricing:
https://github.com/saulwiggin/finance-with-python/blob/master/Monte%20Carlo%20and%20Pricing%20Exotic%20Options/asian-option.py.
Here is the code:...
0
votes
0
answers
33
views
Why do I get invalid command name ".numbers" error in turtle module?
import random
import turtle
import time
bonus = 0
def main():
global writeT
writeT = turtle.Turtle()
global rchance
rchance = 0
Day = 0
global Steve
#0 name 1:days 2money ...
0
votes
2
answers
28
views
Slice two datetime objects with Python
I have two date time objects in Python 2.7.
The first looks like this:
2018-09-22 00:00:00
and the second looks like this:
1899-12-30 17:20:59
I would like to end up with the dates from the first ...
1
vote
2
answers
72
views
Python 2 - Searching for all the values of a key in a dict with nested dicts and lists
I've got a dictionary with nested dicts and list inside it.
This structure allows a key to be repeated inside the dict, being able to have different values (either from a list of dicts, or from ...
1
vote
0
answers
83
views
Type comment list of values
I'm using Jython 2.1, so I cannot use type annotations ({var}: {type}) but I use type comments (# type: {type} for variables and # type: ({param_type}) -> {ret_type} for functions).
I would like to ...
0
votes
0
answers
36
views
how can we creating detection version on python 2 and python 3
Hello there i need some help for a little, i working on python version 3/2, i wanna create a system detection on python script and how can i solve the problem like this:
try:
import platform
...
0
votes
0
answers
57
views
ScyllaDB installation fails on RHEL9
I am installing ScyllaDB (as described here: https://www.scylladb.com/download/?platform=rhel&version=scylla-5.2#open-source) on RHEL9 box (running on AWS EC2).
Getting this error:
Error:
Problem ...
0
votes
1
answer
105
views
python2 socket.send to python3 Replica not substitute
I have a script that use the module socket inside a python2 script.
I would like to upgrade it to a python3 script.
After searching Difference between Python3 and Python2 - socket.send data and Python ...
-1
votes
1
answer
34
views
Text file line count - different number in python2 vs python3
I am reading a text file using this command:
print(len(list(open(filename))))
Now, when I run it in Python2 I get 5622862 lines, but when I read it with Python3 I get 5622865 lines. How can it be? ...
0
votes
0
answers
76
views
Python 3.10 Popen behavior after update from 2.7
I am updating some old python scripts from 2.7 to 3.10 and can't figure out the behavior of one function.
def export_from_source(self):
self.dt_start = datetime.now()
p = subprocess.Popen(self....
1
vote
0
answers
26
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(...
2
votes
5
answers
86
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
42
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
52
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
765
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
155
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
65
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
1
answer
320
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
45
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
65
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
121
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
19
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
201
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
1k
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
311
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
70
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
121
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
241
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
112
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
99
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
69
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
393
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
109
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
1
answer
94
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
1
answer
365
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
320
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
2
answers
578
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
41
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
167
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 ...
3
votes
1
answer
1k
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
459
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
194
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
107
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
953
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 ...