python - Passing a variable from another function
问题描述
import os
import shutil
def listdirectory():
global computername
computername = input("What is the computer name? ")
completepathlist = fr"\\{computername}\C$\Users"
return os.listdir(completepathlist)
def username():
global completepath
global usernameinput
usernameinput = input("What is the user name? ")
completepath = fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"
def programrunningcheck():
password = input("What is your password? ")
command = "taskkill /s " + str(computername) + " /u " + str(usernameinput) + " /p " +password+ " /im chrome.exe"
print(command)
os.system(command)
def deletegoogleapp():
shutil.rmtree(completepath)
#Functions being called
print(listdirectory())
username()
programrunningcheck()
deletegoogleapp()
Everything works up until deletegoogleapp
function is called and receive a
\\DESKTOP-62A8SSM\C$\Users\"function username at 0x010C8B28\AppData\Local\Google
looks to be not passing the variable completepath
from another function to the googleapp
function.
解决方案
您需要存储 的返回值username
,现在,您没有将任何内容传递给deletegoogleapp
. 所以你可以这样做:
u <- username()
programrunningcheck()
deletegoogleapp(u)
鉴于返回的路径u
有效,这应该可以工作。
推荐阅读
- c# - 启动 out-gridview 后 Winform 调整大小/缩小
- java - 我怎么可能在 onCreate() 中为我的 Session 获得错误的类?
- php - 将输入类型文件值插入mysql数据库
- java - 最后在java中块覆盖
- postgresql - PostgreSql 找到第 n 个数字
- dart - 单击 Gridview 项时将数据传递到另一个屏幕
- python - 在python中将正则表达式应用于xml文件
- position - 设置 JFace TreeViewer 的滚动条位置
- sockets - python套接字连接无法接收完整消息
- css - 如何在 angularDart 项目中将 div 图像与中心对齐?