function

Python - sorting strings numerically

风格不统一 提交于 2021-02-05 10:44:07
问题 I'm using python to merge two files together to create a new one, the data in both files have an id at the start of every string which I want to sort so they're both in the same order and can be merged. To do this I've used .sort() so that they're both arranged in the same order and the comments match the details. However, I'd now like to reorder them so that they go 1, 2, 3, 4... instead of 1, 10, 100, 1000, 1001, 1002 etc but I am having difficulties since the number is the start of a

Running a thread with Tkinter object

流过昼夜 提交于 2021-02-05 09:46:39
问题 When I push the button the scan_open_ports start working until the line ip_list.curselection() where it stops, this line blocks the running of the function... I wanted to know why and how to fix that? Thanks def scan_open_ports(): #long runtime function print "Asdasd\" ip_list.curselection() def thr_open_ports(): threading.Thread(target=scan_open_ports).start() ip_list = Listbox() scan_ports = Button(window, text="Scan Open Ports", command= thr_open_ports, height = 10, width = 20) 回答1: I have

Getting Input from a Function - c++ [duplicate]

心不动则不痛 提交于 2021-02-05 09:42:52
问题 This question already has answers here : When I change a parameter inside a function, does it change for the caller, too? (4 answers) Closed 5 years ago . I've been having a problem in c++ where I call a function which assigns some values to things, but those assignments are lost after the function has been completed. Here is my code: #include <iostream> #include <string> using namespace std; void Input(string a, string b){ cout << "Input a: \n"; cin >> a; cout << endl; cout << "Input b: \n";

Getting Input from a Function - c++ [duplicate]

蓝咒 提交于 2021-02-05 09:42:38
问题 This question already has answers here : When I change a parameter inside a function, does it change for the caller, too? (4 answers) Closed 5 years ago . I've been having a problem in c++ where I call a function which assigns some values to things, but those assignments are lost after the function has been completed. Here is my code: #include <iostream> #include <string> using namespace std; void Input(string a, string b){ cout << "Input a: \n"; cin >> a; cout << endl; cout << "Input b: \n";

Error message saying variable not defined when it is. Python

一个人想着一个人 提交于 2021-02-05 09:41:38
问题 I am trying to create a simple encryption program in python using functions but am having a problem where I get an error message when I run the program saying ('msgReversed' is not defined) when it is. the program works by first reversing the users message and then shifting the letters to the value of the Key alphabet=("abcdefghijklmnopqrstuvwxyz ") def userInput(): plaintext=input("Enter message to encript") k=int(input("Enter encription Key you want to use (1-25)")) return (k,plaintext) def

Function variable scope in python

徘徊边缘 提交于 2021-02-05 09:38:26
问题 let's say we have two functions: def ftpConnect(): ftp = FTP('server') ftp.login() ftp.cwd('/path') def getFileList(): ftpConnect() files = ftp.nlst() print(files) If I call the getFileList() function it won't work because it doesn't know the ftp var. I know that if I declare the ftp variable inside ftpConnect() function as global it will work, but I was wondering if there is a better / more elegant way of doing it. 回答1: In my opinion, the most elegant solution would be to make a FTP-class,

Computing a function name from another function name

ε祈祈猫儿з 提交于 2021-02-05 09:28:12
问题 In python 3.4, I want to be able to do a very simple dispatch table for testing purposes. The idea is to have a dictionary with the key being a string of the name of the function to be tested and the data item being the name of the test function. For example: myTestList = ( "myDrawFromTo", "myDrawLineDir" ) myTestDict = { "myDrawFromTo": test_myDrawFromTo, "myDrawLineDir": test_myDrawLineDir } for myTest in myTestList: result = myTestDict[myTest]() The idea is that I have a list of function

Memory error utilizing numpy arrays Python

好久不见. 提交于 2021-02-05 09:27:18
问题 My original list_ function has over 2 million lines of code and I get a memory error when I run the code that calculates . Is there a way I could could go around it. The list_ down below isa portion fo the actual numpy array. Pandas data: import pandas as pd import math import numpy as np bigdata = 'input.csv' data =pd.read_csv(Daily_url, low_memory=False) #reverses all the table data values data1 = data.iloc[::-1].reset_index(drop=True) list_= np.array(data1['Close'] Code: number = 5 list_=

Trying to wrap my head around PowerShell - functions, aliases etc

放肆的年华 提交于 2021-02-05 09:16:25
问题 I'm a seasoned C# programmer, but so far, I have only barely dabbled in PowerShell (having used another alternate Windows command line product so far). I'm trying to automate some Git stuff, and I've run into some difficulties and can't seem to find any solution to these... (and no video tutorial or blog post seems to have helped much so far, either). What I'm trying to do is define functions and aliases that make my work with Git in PowerShell more comfortable - and yes, I know about Posh

Return a reference to an Excel Worksheet from a PowerShell Function

天大地大妈咪最大 提交于 2021-02-05 09:01:52
问题 For the sake of code readability, I'd like to move my Excel stuff to a function and leave the worksheet object available to write cell values as my program processes stuff. How do I call a function that creates an Excel spreadsheet and return a worksheet reference so I can continue to access the open/active Excel app object I've created? Function Create-Excel-Spreadsheet() { # open excel $excel = New-Object -ComObject excel.application $excel.visible = $True # add a worksheet $workbook =