好的,我们假设我已经在C#中构建了一个应用程序,当你使用这个应用程序时,它使用了很多计算机的内存,现在我想要做一些事情,当它闲置或者我没有使用它时,它会停止使用内存,但我可以回去开始工作,在我离开的地方.是否有任何地方临时暂停应用程序所以它不使用Ram?
我曾经使用IDLE在Python 2.7中以交互方式编程.在2.7中,当我做的事情如下:
map(... some fn ..., ... some collection ...)
Run Code Online (Sandbox Code Playgroud)
要么
filter(... some fn ..., ... some collection ...)
Run Code Online (Sandbox Code Playgroud)
我将结果作为应用函数产生的集合.
升级到Python 3.2后,当我这样做时,我只得到"过滤器对象"或"地图对象",并且必须手动迭代集合才能看到结果.
这是否打算并且您是否知道任何Python 3.2 IDE在打印功能输出方面的行为与旧IDLE相似?我基本上都在寻找"REPL for Python".
我有一个列表,A = [1, 2, 3, ..., n]
并希望重复移动列表以获取列表列表.第一行应该是A
第二行[2, 3, 4, ...]
,第三行[3, 4, 5, ...]
,直到最后一行[n, 0, 0, ...]
.最后一列中缺少的元素应为零.我试图单独放置它们,但是n> = 100因此手动填充零会花费很长时间.我该怎么做呢?
为numpy数组编辑相同的问题,这就是我真正拥有的.
我有使用 tkinter 的代码,我可以从 IDLE 运行它,但是AttributeError: 'module' object has no attribute 'font'
当它从命令行运行时会抛出异常。其他 tkinter 程序工作正常,但任何使用 tkinter 包的 font.py 的东西都会给我这个错误。
我检查了我的 python 文件,并且 c:/Python34/Lib/tkinter/font.py 就在那里。我不知道为什么,从命令行,它认为字体是一个属性,而不是 tkinter 包的模块。
示例代码:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
test_font = tk.font.Font(size=12,weight='bold')
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我一直在努力寻找在文档中具有特定文件夹位置的Windows资源管理器的打开状态。我试过了:
import subprocess
subprocess.Popen(r'explorer /select,mypath')
Run Code Online (Sandbox Code Playgroud)
欢迎所有建议!!
假设我们已经在Python或IDLE shell中运行了以下代码行:
print("hai")
Run Code Online (Sandbox Code Playgroud)
屏幕上显示以下内容:
hai
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎违反直觉,因为print(arg)是一个void函数,因此在求值时始终返回None;NoneType是python中的数据类型,但是当表达式对其求值时,它不会显示在窗口上,而整数是:
5
Run Code Online (Sandbox Code Playgroud)
使它显示在屏幕上(在shell上运行):
5
Run Code Online (Sandbox Code Playgroud)
是否将此非显示行为硬编码到python中,仅是NoneType数据的功能?
我之所以要问这个问题,是因为所谓的“输出”似乎存在歧义,而且我担心这种歧义会使我的中期工作变得相当灾难性。例如,考虑以下代码行…
…在shell中运行:
5
Run Code Online (Sandbox Code Playgroud)
使它出现在屏幕上:
5
Run Code Online (Sandbox Code Playgroud)
…编译并运行:
5
Run Code Online (Sandbox Code Playgroud)
没有使任何东西出现在屏幕上。
-
表达式5在Python中的计算结果为整数5,但整数5的输出结果与...相同
print(5)
Run Code Online (Sandbox Code Playgroud)
…在屏幕上输出“ 5”?以及print(5)函数调用求值的NoneType数据对象如何?那也将是输出吗?
我想我的问题的实际后果是:说有人问你这个问题:
这行代码的输出是什么?
print(5)
Run Code Online (Sandbox Code Playgroud)
正确的答案是:
(一种)。
5
没有
(b)。
5
要么
(C)。
没有 ?
从好的角度来说,这个问题怎么样:
这行代码的输出是什么?
5
正确的答案是:
(一种)。
要么
(b)。
5
以上两个问题的答案取决于两点:
“输出到底是什么构成的?评估值是输出吗?还是输出的字面意思就是:按回车键后屏幕会是什么样?
“我们如何运行代码很重要?由于在TextEdit中编写了代码行,然后对其进行编译然后运行,与在外壳中键入代码行并按回车键相比,屏幕上出现的内容有所不同。”
我想为使用 gTTS 的语音助手创建 python 代码。我运行了代码,但它没有像它显示的那样工作,
回溯(最近一次调用最后一次):
文件“/Users/niallquadros/Desktop/voiceassistant.py”,第 1 行,来自
<module>
gTTS 导入 gTTSModuleNotFoundError:没有名为“gTTS”的模块
相反,它应该给我结果,并充当语音助手。
这是我在 MacBook Air 2019 上使用 python (3.7.4) 编写的代码
from gTTS import gTTS
import speech_recognition as sr
import os
import webbrowser
import satplib
def talkToMe(audio):
print (audio)
tts = gTTs(text=audio, lang='en')
tts.save('audio.mp3')
os.system('mpg123 audio.mp3')
#Listen for commands
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('I am ready for your next command')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration = 1)
audio = r.listen(source)
try:
command = …
Run Code Online (Sandbox Code Playgroud) 我正在关注PySimpleGUI文档并在进行过程中进行自己的编辑。我对它很陌生,并且有使用 Tkinter 的经验。Tkinter 中有一个文本框,您可以通过代码获取Text(window, width=?, height=?, wrap=WORD, background=yellow)
。但是在 PySimpleGUI 中使用类似的代码:layout = [[sg.Text('Some text on Row 1')]]
- 创建一个标签。我的代码是:
import PySimpleGUI as sg
sg.theme('DarkAmber') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Text('Some text on Row 1')],
[sg.Text('Enter something on Row 2'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Close Window')],
[sg.Text('This is some text', font='Courier 12', text_color='blue', background_color='green')],
[sg.Listbox(values=('value1', 'value2', 'value3'), size=(30, 2), key='_LISTBOX_')]]
# Create the Window
window = …
Run Code Online (Sandbox Code Playgroud) 我确定这是一个简单的错误,我已将其本地化为代码中的特定位置:
class NewProduct(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tLabel = ttk.Label(self, text="Title: ", font=NORM_FONT).grid(row=0, padx=5, pady=5)
qLabel = ttk.Label(self, text="Quantity: ", font=NORM_FONT).grid(row=1, padx=5, pady=5)
pLabel = ttk.Label(self, text="Price: $", font=NORM_FONT).grid(row=2, padx=5, pady=5)
te = ttk.Entry(self).grid(row=0, column=1, padx=5, pady=5) # Add validation in the future
qe = ttk.Entry(self).grid(row=1, column=1, padx=5, pady=5)
pe = ttk.Entry(self).grid(row=2, column=1, padx=5, pady=5)
saveButton = ttk.Button(self, text="Save", command=lambda: self.save(self.te.get(), self.qe.get(), self.pe.get()))
#WHY IS THIS WRONG!!!!!???!?!?!?!?!?
saveButton.grid(row=4, padx=5)
cancelButton = ttk.Button(self, text="Cancel", command=lambda: popupmsg("Not functioning yet."))
cancelButton.grid(row=4, …
Run Code Online (Sandbox Code Playgroud) 我得到了AttributeError:'unicode'对象没有在这个问题的标题中指定的属性'sleep',我无法弄清楚为什么它会抛出该错误消息.这是自动发布facebook的自动脚本.如果有人知道我的代码有什么问题,我告诉我.代码在这里
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import traceback
import string
import xlrd
#taking inputs from user-----------------------------------
delay=input('Set Time: ')
limit=input('Set Post Limit: ')
valuee=limit
count=0
start=0
end=valuee
#----------------------------------------------------------
#open file for taking multiple accounts-------------------
f=open('Accounts.csv')
data=f.readlines()
i=0
for value in data:
values=value.split(',')
password=values[1]
user_name=values[0]
#Condition for next URLs--------------------------
if count>=1:
start=limit
end=start + valuee
limit=end
count+=1
#-----------------------------------------------
chrome_options = webdriver.ChromeOptions() #going to chrome options
chrome_options.add_argument("--start-maximized")
prefs = {"profile.default_content_setting_values.notifications" : 2 #turn off all notifications
,"profile.managed_default_content_settings.images": …
Run Code Online (Sandbox Code Playgroud) python ×7
tkinter ×3
python-3.x ×2
python-idle ×2
automation ×1
c# ×1
gtts ×1
numpy ×1
pysimplegui ×1
python-2.7 ×1
python-3.7 ×1
selenium ×1
sleep ×1
web-scraping ×1