output

How to store randomly generated lists in python

How to store randomly generated lists in python Question: I am a mathematician with limited programming experience, but am building a neural network to generate curves with certain properties. I’ve built a training set which looks like a list of 1000 randomly generated numbers between -1 and 1 as follows: import random N = 1000 …

Total answers: 3

Pyfiglet/Python – Print Pyfiglet ASCII in one line

Pyfiglet/Python – Print Pyfiglet ASCII in one line Question: This is my code to print "x t e k k y" whit a cool ASCII font using pyfiglet, but the output always displays in 2 lines, whith gives a bad aestethic, is there any way to fix that? from pyfiglet import figlet_format from termcolor import …

Total answers: 1

5.1.1 Basic Funtion Call Output

5.1.1 Basic Funtion Call Output Question: I have been trying to get this to output correctly. It is saying I’m not adding a line break at the end. I was wondering, how I could add the line break? From my understanding the code is for the most part right. I also need to have it …

Total answers: 1

How to sort numbers from two different txt files then save them as one txt file

How to sort numbers from two different txt files then save them as one txt file Question: Could anyone help please. I have the following task: Create a new Python file in this folder called ​combined.py  Create a text file called ​numbers1.txt that contains Integers which are sorted from smallest to largest.  Create another text …

Total answers: 3

printing Timedelta to nanosecond precision

printing Timedelta to nanosecond precision Question: How can one print directly pandas Timedelta with nanosecond precision? For now, my solution is to add to Timedelta some dummy date to be able to do it. Hopefully, there is a better solution. import pandas as pd time = pd.Timedelta(50400001747113) print(time) # 0 days 14:00:00.001747 print(pd.Timestamp(‘2019-10-02’) + time) …

Total answers: 4

.write() is only writing to output file in the last iteration of a loop

.write() is only writing to output file in the last iteration of a loop Question: I’m trying to open a bunch of files in a directory, remove some words from those files and write the output to a file in the same directory. I’m having problems when trying to write to the output file. There …

Total answers: 1

How to Print in Python 2.7 without newline without buffering

How to Print in Python 2.7 without newline without buffering Question: I have a need in Python 2.7 to print text to the console without newline characters, so I can continue writing more text on that same line later with future code. My current implementation involves importing the Python 3 print function from the future …

Total answers: 1

Python: How to read stdout of subprocess in a nonblocking way

Python: How to read stdout of subprocess in a nonblocking way Question: I am trying to make a simple python script that starts a subprocess and monitors its standard output. Here is a snippet from the code: process = subprocess.Popen([path_to_exe, os.path.join(temp_dir,temp_file)], stdout=subprocess.PIPE) while True: output=process.stdout.readline() print “test” The problem is that the script hangs on …

Total answers: 3

How to save output from python like tsv

How to save output from python like tsv Question: I am using biopython package and I would like to save result like tsv file. This output from print to tsv. for record in SeqIO.parse(“/home/fil/Desktop/420_2_03_074.fastq”, “fastq”): print (“%s %s %s” % (record.id,record.seq, record.format(“qual”))) Thank you. Asked By: Vonton || Source Answers: The following snippet: from __future__ …

Total answers: 5

list comprehension replace for loop in 2D matrix

list comprehension replace for loop in 2D matrix Question: I try to use list comprehension to replace the for loop. original file is 2 3 4 5 6 3 1 2 2 4 5 5 1 2 2 2 2 4 for loop line_number = 0 for line in file: line_data = line.split() Cordi[line_number, :5] …

Total answers: 1