2,887 questions
1
vote
1
answer
70
views
How to connect to an Oracle7 database
I have an ancient Oracle7 database (version 7.3.4.5.0) that I need to extract some data from.
I mainly work with Python, so naturally I started looking at oracledb. However, it looks like the oldest ...
1
vote
0
answers
52
views
How to open and use NPZ files to DICOM files
a few months ago I was granted permission to download and use the RAD-ChestCT dataset from https://zenodo.org/doi/10.5281/zenodo.6406113 and it was in a numpy compressed 3D numpy array (npz format) ...
0
votes
2
answers
89
views
multiprocess not working correctly (Windows, Python2)
So I run this:
import time
from multiprocessing import Process
def ghello():
print ("hello world g")
def fhello():
print("hello world f")
if __name__ == "...
0
votes
1
answer
32
views
dlib's load_rgb_image() couldn't be found
So I have successfully installed dlib version 18.17.0 that's compatible with Python 2. Classes such as simple_object_detector could be instantiated and returned and instance of the object. But a ...
0
votes
0
answers
41
views
Cannot install Database-library package in Python2 using pip
I am new to python and moving one test from one (working) to another physical machine (new).
in the process , One of python file has -> from DAL.database import DBC
when I do 'pip2 freeze' on both ...
0
votes
1
answer
165
views
Create virtual environment with python 2.7.18 from VScode
I want to create a virtual environment in VS Code with python version 2.X. If I remember correctly, I was able to create an environment for Python 2 two months ago, but I can't do so anymore.
I've ...
0
votes
1
answer
55
views
Jython API copy method does not seem to work
I am using the following Python 2 method, in which the parameter of the method is a Jython object (task) :
def getTaskPosition(task):
"""Gets the current position of the task in its ...
0
votes
1
answer
38
views
Task index out of bounds in Python 1 Script
My problem is very similar to a previous issue posted in here :
IndexError: index out of bounds
I am adapting the code developed for an XL-Release Community plugin. This original comunity "plugin&...
0
votes
0
answers
15
views
Iterate a Python Dictionary
I have the following method :
def apply_encoding_and_validate_size_of_items_of_list(self):
list_with_sizes = []
for key, value in self.dictionary_of_tasks.items():
if not value:
...
0
votes
0
answers
87
views
Apache Error 500: Problem with cgi script execution on python 2.4
When trying to access a python file via http request. I get an error:
Internal server error
The server encountered an internal error or misconfiguration and was unable to fulfill your request.
Please ...
0
votes
1
answer
124
views
How to manipulate/join multiple strings containing UTF-8 characters
My code needs to be compatible with both Python 2.x and 3.x versions. I am getting both string as input to my function, and I need to do some manipulation on those:
if len(str1) > 10:
str1 = ...
0
votes
0
answers
29
views
Canonical way to ensure float point division across py2 and py3? [duplicate]
I have a function that needs to support both py2 and py3, unfortunately.
Currently, there's a division op:
n = a / b
a and b are usually whole numbers, but represented as floats, but from what I can ...
2
votes
0
answers
62
views
Why would different characters impact the order of the output for this getPositions method? [duplicate]
class Solution(object):
def getPositions(self, s):
mapping = {}
for i in range(len(s)):
if s[i] not in mapping:
mapping[s[i]] = [i]
elif s[i]...
0
votes
0
answers
64
views
Shouldn't importing print_function change the keyword.kwlist in python2?
In python-2.7, shouldn't the keyword.kwlist be updated after importing print_function from __future__?
Python 2.7.18 (default, Feb 1 2021, 00:00:00)
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on ...
0
votes
0
answers
63
views
Problems with pyenv virtualenv and Django 1.6
I installed python 2.7 using pyenv to run an older project that still uses Django 1.6, but I can't get the path to work.
Even thou I have the virtualenv that I created with 2.7 activated, and all pip ...
0
votes
1
answer
48
views
Python 2 vs Python 3 - Encoding [duplicate]
I have a simple code:
# -*- coding: utf-8 -*-
text = "12É45678"
print(len(text))
See the Upper E with accent
Then
when I run from python 2, the result is 9
when I run from python 3, the ...
0
votes
1
answer
409
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
2
answers
296
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
1
answer
137
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
0
answers
88
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
1k
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
41
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
53
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
83
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 ...
2
votes
0
answers
178
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
61
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
1
answer
171
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
46
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
142
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....
0
votes
0
answers
30
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
97
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
78
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
75
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
3k
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
1
answer
752
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
75
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&...
0
votes
2
answers
24
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
394
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 ...
1
vote
1
answer
4k
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
578
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
151
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
365
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
311
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
182
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
151
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
133
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
1k
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
1
answer
290
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
487
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
394
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:...