我是Python
编程的新手。我从互联网上下载了一个python项目。现在我想在下载的项目中更改几行代码。我在mac Python
上使用OSX
IDLE来更改代码。但即使在执行程序时更改代码,它也会运行旧代码!如何在下次运行时对代码进行更改时对代码进行更改。
以下是我的项目如何运作的结构。
File1 somethingone.py File2 somethingtwo.py< =这里我正在导入somethingone.py
我在terminal =>上执行此操作python somethingtwo.py
编辑: 这是编辑前的somethingone.py中的一个函数
def download_photo(self, media_id, path='foldername/', filename=None,
description=False):
delay.small_delay(self)
if not os.path.exists(path):
os.makedirs(path)
if description:
media = self.get_media_info(media_id)[0]
caption = media['caption']['text']
with open('{path}{0}_{1}.txt'.format(media['user']['username'], media_id, path=path), 'w') as f:
f.write(caption)
photo = super(self.__class__, self).downloadPhoto(media_id, filename, False, path)
if photo:
return photo
self.logger.info("Media with %s is not %s ." % (media_id, 'downloaded'))
return False
编辑后
def download_photo(self, media_id, path='foldername/', filename=None,
description=False):
delay.small_delay(self)
if not os.path.exists(path):
os.makedirs(path)
if description:
media = self.get_media_info(media_id)[0]
caption = ""
with open('{path}{0}_{1}.txt'.format(media['user']['username'], media_id, path=path), 'w') as f:
f.write(caption)
photo = super(self.__class__, self).downloadPhoto(media_id, filename, False, path)
if photo:
return photo
self.logger.info("Media with %s is not %s ." % (media_id, 'downloaded'))
return False
这是来自somethingtwo.py的函数,其中使用了上面的函数:
def myfunc(obj, new_media_id, path=POSTED_MEDIAS):
if exists_in_posted_medias(new_media_id, path):
obj.logger.warning("Media {0} was uploaded earlier".format(new_media_id))
return False
photo_path = obj.download_photo(new_media_id, description=True)
return photo_path