我有三个模块:
one.py
:
def abc():
print "Heeeeeeeeeeeiiiiiioooooooooo"
Run Code Online (Sandbox Code Playgroud)
two.py
:
import one
def defg():
one.abc()
Run Code Online (Sandbox Code Playgroud)
three.py
:
import os
from time import sleep
import two
two.defg()
sleep(20)
directory = os.listdir('.')
for filename in directory:
if filename[-3:] == 'pyc':
print '- ' + filename
os.remove(filename)
Run Code Online (Sandbox Code Playgroud)
我有三个疑问.请帮助我.
当我three.py
第一次跑one.pyc
,two.pyc
并将被创建.我可以看到它,因为我延迟了20秒.执行该语句后os.remove(filename)
,它们将被删除.直到这里它的罚款.
再次没有关闭IDLE以及我运行的脚本three.py
.这次没有.pyc
创建文件.为什么会这样?
如果我关闭IDLE以及脚本,.pyc
将像以前一样创建.
为什么编译后的代码没有再次创建和agin?
此外,如果我进行更改,one.py
如果我在没有关闭shell的情况下运行它将不会显示.我也需要一个解决方案.
第三个疑问是,如果编译的代码第一次被删除,那么第二次运行如何在没有的情况下得到相同的结果.pyc
?
希望找到解决方案......
我有一个.txt文件,如:
Symbols from __ctype_tab.o:
Name Value Class Type Size Line Section
__ctype |00000000| D | OBJECT |00000004| |.data
__ctype_tab |00000000| r | OBJECT |00000101| |.rodata
Symbols from _ashldi3.o:
Name Value Class Type Size Line Section
__ashldi3 |00000000| T | FUNC |00000050| |.text
Run Code Online (Sandbox Code Playgroud)
如何解析此文件并获取类型为FUNC的函数?另外,从这个txt我怎么解析和提取.o名称?
我如何通过列式解析或其他方式获得它们.
我需要立即帮助......像往常一样等待合适的解决方案
在列表中附加是可能的.但是我如何在字典中附加?
Symbols from __ctype_tab.o:
Name Value Class Type Size Line Section
__ctype |00000000| D | OBJECT|00000004| |.data
__ctype_tab |00000000| r | OBJECT|00000101| |.rodata
Symbols from _ashldi3.o:
Name Value Class Type Size Line Section
__ashldi3 |00000000| T | FUNC|00000050| |.text
Symbols from _ashrdi3.o:
Name Value Class Type Size Line Section
__ashrdi3 |00000000| T | FUNC|00000058| |.text
Symbols from _fixdfdi.o:
Name Value Class Type Size Line Section
__fixdfdi |00000000| T | FUNC|0000004c| |.text
__fixunsdfdi | | U | NOTYPE| | |*UND*
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建一个字典: …
我想知道Python中的计时器.
假设我有一个代码片段,如:
def abc()
print 'Hi'
print 'Hello'
print 'Hai'
Run Code Online (Sandbox Code Playgroud)
我想每1秒打印一次.最多三次;即; 第一秒我需要检查printf,第二秒我需要在第3秒检查.
在我的实际代码变量中,值将被更新.我需要捕获所有变量的更新.
任何人都可以告诉我如何做到这一点.
我正在为Python脚本创建一个接口.稍后我将使用Python Python脚本进行自动化测试.是否有必要我必须在我的代码中使用类.现在我已经用字典,列表,函数,全局变量和局部变量创建了代码.
是必要的吗?
帮助我.
假设我有一个函数定义:
def test():
print 'hi'
Run Code Online (Sandbox Code Playgroud)
每当我给出一个参数时,我得到一个TypeError.
现在,我想把def语句放在try中.我该怎么做呢?
如果我在python中执行以下操作,
string = raw_input('Enter the value')
Run Code Online (Sandbox Code Playgroud)
它会回来
输入值
等到我在提示中输入内容.
有没有办法检索/收集我在变量中输入的输入string
?
我想以下列方式使用输入的值:
if dict.has_key('string'):
print dict[string]
Run Code Online (Sandbox Code Playgroud)
注意:我之前犯了使用错误,raw_string
但我想说raw_input
for i in range(0,3):
j = 0
print 'incrementing '
j += 1
print j
Run Code Online (Sandbox Code Playgroud)
版画
incrementing
1
incrementing
1
incrementing
1
Run Code Online (Sandbox Code Playgroud)
如何保持'j'的值以便打印:
1
2
3
Run Code Online (Sandbox Code Playgroud) 我得到了引用计数的概念
所以,当我执行"del astrd"时,引用计数降为零,astrd被gc收集?
这是示例代码.这些代码是我在昨天的问题之后开发的:链接文本
one.py:
def abc():
print "Hello"
print "123"
print '345'
Run Code Online (Sandbox Code Playgroud)
two.py:
import one
#reload(one)
#def defg():
one.abc()
Run Code Online (Sandbox Code Playgroud)
three.py:
import os,sys,gc
from time import sleep
import two
#reload(two)
#two.defg()
sleep(20)
directory = os.listdir('.')
for filename in directory:
if filename[-3:] == 'pyc':
print '- ' + filename
print sys.getrefcount(filename)
file_name = os.path.splitext (filename)[0]
del file_name # remove the local reference
del sys.modules[os.path.splitext (filename)[0]] # removes import
gc.collect() # garbage collect
#del sys.modules[filename]
#del filename
#os.remove(filename)
Run Code Online (Sandbox Code Playgroud)
我在three.py中所做的是对还是不对?有没有必要的步骤?如果是,为什么?
请帮我解决这个问题.
我不知道为什么结肠在第二次左转
>>> print '%5s' %':'
:
>>> print '%5s' %':' '%2s' %':'
: :
Run Code Online (Sandbox Code Playgroud)
请帮帮我