python-3.2

python centre string using format specifier

柔情痞子 提交于 2020-01-09 19:04:26
问题 I have a string called Message. Message = "Hello, welcome!\nThis is some text that should be centered!" Yeah, it's just a test statement... And I'm trying to centre it for a default Terminal window, i.e. of 80 width, with this statement: print('{:^80}'.format(Message)) Which prints: Hello, welcome! This is some text that should be centered! I'm expecting something like: Hello, welcome! This is some text that should be centered! Any suggestions? 回答1: You need to centre each line separately: '

Unable to write to stdin in subprocess

空扰寡人 提交于 2020-01-06 08:43:16
问题 i am unable to pass in commands to stdin in python 3.2.5. I have tried with the following 2 approaches Also: This question is a continuation of a previous question. from subprocess import Popen, PIPE, STDOUT import time p = Popen([r'fileLoc/uploader.exe'],shell = True, stdout=PIPE, stdin=PIPE, stderr=STDOUT) p.stdin.write('uploader -i file.txt -d outputFolder\n') print (p.communicate()[0]) p.stdin.close() i also get numbers such as 96, 0, 85 returned to me when i try the code in the IDLE

SQLAlchemy+pymysql Error: sqlalchemy.util.queue.Empty

十年热恋 提交于 2020-01-04 12:09:19
问题 Trying to run Python3.2, SQLAlchemy0.8 and MySQL5.2 on Ubuntu using Eclispse but I keep getting the error below. Am using pymysql (pymysql3 actually) engine. module monitor from sqlalchemy import create_engine, MetaData from sqlalchemy.ext.declarative import declarative_base Engine = create_engine('mysql+pymysql://user:mypass@localhost/mydb') Base = declarative_base(Engine) Metadata = MetaData(bind=Engine) from sqlalchemy.orm import sessionmaker from sqlalchemy import Table, Column, Integer

Finding the baseaddress of a running process

霸气de小男生 提交于 2020-01-02 07:23:27
问题 Ive got the following code: import subprocess from ctypes import * #-Part where I get the PID and declare all variables-# OpenProcess = windll.kernel32.OpenProcess ReadProcessMemory = windll.kernel32.ReadProcessMemory processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID) ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)) All this is working flawless, but since some processes uses a so called BaseAddress or StartAddress . And in my case the size of this

DreamPie doesn't work with Python 3.2

谁说胖子不能爱 提交于 2020-01-02 05:24:14
问题 My favorite Python shell is DreamPie and I want to use it with Python 3.2. I've used the "add interpreter" DreamPie app and added Python 3.2. When opening the Python 3.2 DreamPie instance I get the following error message: Indeed, Python 3.2 isn't mentioned on the DreamPie website as supported, but I still want to know if there's a way to make it work anyway. 回答1: A quick search of the DreamPie issues found Can't launch python 3.2 which contains the following workaround in the first comment:

Uninstall python 3.2 on mac os x 10.6.7

我是研究僧i 提交于 2019-12-30 01:13:13
问题 According to the documentation from python.org, python 3.2 install on mac os requires an upgrade to tcl/tk 8.5.9 (for use of IDLE). In my haste, I have done both. Now my friend told me that python 3 is not recommended yet because only the built-ins and a few modules have been released for 3. The stable one so far is 2.7 (especially if one wants to make extensive use of a variety of modules). My machine has both 2.6.1 and 3.2 (because some OS services make use of 2.6.1 that comes as default

debugging pickle

流过昼夜 提交于 2019-12-29 01:39:09
问题 I'm trying to pickle quite an involved object hierarchy and getting the exception: pickle.PicklingError: Can't pickle <class 'function'>: attribute lookup builtins.function failed Are there any reasonable methods one can use to test the pickleablility of an object hierarchy? My aim would be to find the location of the offending function 回答1: To do this, I'd use dill, which can serialize almost anything in python. Dill also has some good tools for helping you understand what is causing your

How to read an array of integers from single line of input in python3

送分小仙女□ 提交于 2019-12-28 06:34:08
问题 I want to read an array of integers from single line of input in python3. For example: Read this array to a variable/list 1 3 5 7 9 What I have tried arr = input.split(' ') But this does not convert them to integers. It creates array of strings arr = input.split(' ') for i,val in enumerate(arr): arr[i] = int(val) 2nd one is working for me. But I am looking for an elegant(Single line) solution. 回答1: Use map : arr = list(map(int, input().split())) Just adding, in Python 2.x you don't need the

python 3.2 global variable not updating when its in a thread

瘦欲@ 提交于 2019-12-24 11:44:44
问题 I'm making a program and I got into a problem. I have a thread running which has a while loop that checks if a global variable is equal to False, if its equal to True then exit the while loop. The problem is even if i update the global variable to True it still doesn't stop, it just continues on. Code: While loop: while stopIt==False: print(stopIt) # Always prints out False, even when exit() is called # do things... Stopper: def exit(): stopIt = True stopIt variable defenition: global stopIt

How to send a file using scp using python 3.2?

て烟熏妆下的殇ゞ 提交于 2019-12-24 04:12:10
问题 I'm trying to send a group of files to a remote server through no-ack's python byndings for libssh2, but I am totally lost regarding the library usage due to the lack of documentation. I've tried using the C docs for libssh2 unsuccesfully. Since I'm using python 3.2, paramiko and pexpect are out of the question. Anyone can help? EDIT: I just found some code in no-Ack's blog comments to his post. import libssh2, socket, os SERVER = 'someserver' username = 'someuser' password = 'secret!'