python os path isfile_Python path.isfile方法代码示例

本文整理汇总了Python中os.path.isfile方法的典型用法代码示例。如果您正苦于以下问题:Python path.isfile方法的具体用法?Python path.isfile怎么用?Python path.isfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块os.path的用法示例。

在下文中一共展示了path.isfile方法的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: isUpdatesAvailable

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def isUpdatesAvailable(cls, path):

if sys.version_info < (3, 0):

return False

# pylint: disable=broad-except

if not os.path.isfile(os.path.join(path, "files.xml")):

return True

try:

available = dict()

for it in ET.parse(os.path.join(path, "files.xml")).iter():

if it.tag == "File":

available[it.text] = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")

path = NamedTemporaryFile()

path.close()

urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path.name)

for it in ET.parse(path.name).iter():

if it.tag == "File":

tmp = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")

if not it.text in available or available[it.text] != tmp:

return True

except Exception as e:

print(e)

return True

return False

开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:26,

示例2: readManufacturerSettings

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def readManufacturerSettings(cls, manufacturers, path):

# pylint: disable=broad-except

manufacturers = []

files = [f for f in listdir(path) if isfile(join(path, f))]

if files:

for it in files:

if it.endswith(".obx"):

try:

manufacturers.append(cls.__parse(os.path.join(path, it)))

except Exception as e:

print(e)

continue

#

# Serialize manufacturer from the xml.

#

# @param in

# Input stream.

# Serialized manufacturer.

#

开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:22,

示例3: get_perf

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def get_perf(filename):

''' run conlleval.pl perl script to obtain

precision/recall and F1 score '''

_conlleval = PREFIX + 'conlleval'

if not isfile(_conlleval):

#download('http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl')

os.system('wget https://www.comp.nus.edu.sg/%7Ekanmy/courses/practicalNLP_2008/packages/conlleval.pl')

chmod('conlleval.pl', stat.S_IRWXU) # give the execute permissions

out = []

proc = subprocess.Popen(["perl", _conlleval], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

stdout, _ = proc.communicate(open(filename).read())

for line in stdout.split('\n'):

if 'accuracy' in line:

out = line.split()

break

# out = ['accuracy:', '16.26%;', 'precision:', '0.00%;', 'recall:', '0.00%;', 'FB1:', '0.00']

precision = float(out[3][:-2])

recall = float(out[5][:-2])

f1score = float(out[7])

return {'p':precision, 'r':recall, 'f1':f1score}

开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:25,

示例4: cvt_annotations

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def cvt_annotations(devkit_path, years, split, out_file):

if not isinstance(years, list):

years = [years]

annotations = []

for year in years:

filelist = osp.join(devkit_path,

f'VOC{year}/ImageSets/Main/{split}.txt')

if not osp.isfile(filelist):

print(f'filelist does not exist: {filelist}, '

f'skip voc{year} {split}')

return

img_names = mmcv.list_from_file(filelist)

xml_paths = [

osp.join(devkit_path, f'VOC{year}/Annotations/{img_name}.xml')

for img_name in img_names

]

img_paths = [

f'VOC{year}/JPEGImages/{img_name}.jpg' for img_name in img_names

]

part_annotations = mmcv.track_progress(parse_xml,

list(zip(xml_paths, img_paths)))

annotations.extend(part_annotations)

mmcv.dump(annotations, out_file)

return annotations

开发者ID:open-mmlab,项目名称:mmdetection,代码行数:26,

示例5: ThreadSSH

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def ThreadSSH(self):

try:

self.session = pxssh.pxssh(encoding='utf-8')

if (not path.isfile(self.settings['Password'])):

self.session.login(gethostbyname(self.settings['Host']), self.settings['User'],

self.settings['Password'],port=self.settings['Port'])

else:

self.session.login(gethostbyname(self.settings['Host']), self.settings['User'],

ssh_key=self.settings['Password'],port=self.settings['Port'])

if self.connection:

self.status = '[{}]'.format(setcolor('ON',color='green'))

self.activated = True

except Exception, e:

self.status = '[{}]'.format(setcolor('OFF',color='red'))

self.activated = False

开发者ID:mh4x0f,项目名称:b1tifi,代码行数:18,

示例6: compile_bundle_entry

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def compile_bundle_entry(self, spec, entry):

"""

Handler for each entry for the bundle method of the compile

process. This copies the source file or directory into the

build directory.

"""

modname, source, target, modpath = entry

bundled_modpath = {modname: modpath}

bundled_target = {modname: target}

export_module_name = []

if isfile(source):

export_module_name.append(modname)

copy_target = join(spec[BUILD_DIR], target)

if not exists(dirname(copy_target)):

makedirs(dirname(copy_target))

shutil.copy(source, copy_target)

elif isdir(source):

copy_target = join(spec[BUILD_DIR], modname)

shutil.copytree(source, copy_target)

return bundled_modpath, bundled_target, export_module_name

开发者ID:calmjs,项目名称:calmjs,代码行数:24,

示例7: all_actions

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def all_actions():

"""

Returns a list of all available actions from the *.py files in the actions directory

:return: ist of all available action

"""

result = []

directory = os.getcwd()

while True:

if any([entry for entry in listdir(directory) if entry == ACTIONS_DIR and isdir(os.path.join(directory, entry))]):

break

directory = os.path.abspath(os.path.join(directory, '..'))

actions_dir = os.path.join(directory, ACTIONS_DIR)

for f in listdir(actions_dir):

if isfile(join(actions_dir, f)) and f.endswith("_{}.py".format(ACTION.lower())):

module_name = ACTION_MODULE_NAME.format(f[0:-len(".py")])

mod = get_action_module(module_name)

cls = _get_action_class_from_module(mod)

if cls is not None:

action_name = cls[0][0:-len(ACTION)]

result.append(action_name)

return result

开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:24,

示例8: all_services

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def all_services():

"""

Return as list of all supported service names

:return: list of all supported service names

"""

result = []

for f in listdir(SERVICES_PATH):

if isfile(join(SERVICES_PATH, f)) and f.endswith("_{}.py".format(SERVICE.lower())):

module_name = SERVICE_MODULE_NAME.format(f[0:-len(".py")])

service_module = _get_module(module_name)

cls = _get_service_class(service_module)

if cls is not None:

service_name = cls[0][0:-len(SERVICE)]

if service_name.lower() != "aws":

result.append(service_name)

return result

开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:18,

示例9: all_handlers

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def all_handlers():

global __actions

if __actions is None:

__actions = []

current = abspath(os.getcwd())

while True:

if isdir(os.path.join(current, "handlers")):

break

parent = dirname(current)

if parent == current:

# at top level

raise Exception("Could not find handlers directory")

else:

current = parent

for f in listdir(os.path.join(current, "handlers")):

if isfile(join(current, "handlers", f)) and f.endswith("_{}.py".format(HANDLER.lower())):

module_name = HANDLERS_MODULE_NAME.format(f[0:-len(".py")])

m = _get_module(module_name)

cls = _get_handler_class(m)

if cls is not None:

handler_name = cls[0]

__actions.append(handler_name)

return __actions

开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:26,

示例10: save_picture

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def save_picture(recipes_raw, url):

recipe = recipes_raw[url]

path_save = path.join(

config.path_img, '{}.jpg'.format(URL_to_filename(url)))

if not path.isfile(path_save):

if 'picture_link' in recipe:

link = recipe['picture_link']

if link is not None:

try:

if 'epicurious' in url:

img_url = 'https://{}'.format(link[2:])

urllib.request.urlretrieve(img_url, path_save)

else:

urllib.request.urlretrieve(link, path_save)

except:

print('Could not download image from {}'.format(link))

开发者ID:rtlee9,项目名称:recipe-box,代码行数:18,

示例11: parse_backup_tags

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def parse_backup_tags(backup_dir, tag_name):

"""

Static Method for returning the backup directory name and backup type

:param backup_dir: The backup directory path

:param tag_name: The tag name to search

:return: Tuple of (backup directory, backup type) (2017-11-09_19-37-16, Full).

:raises: RuntimeError if there is no such tag inside backup_tags.txt

"""

if os.path.isfile("{}/backup_tags.txt".format(backup_dir)):

with open('{}/backup_tags.txt'.format(backup_dir), 'r') as bcktags:

f = bcktags.readlines()

for i in f:

splitted = i.split('\t')

if tag_name == splitted[-1].rstrip("'\n\r").lstrip("'"):

return splitted[0], splitted[1]

raise RuntimeError('There is no such tag for backups')

开发者ID:ShahriyarR,项目名称:MySQL-AutoXtraBackup,代码行数:19,

示例12: show_tags

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def show_tags(backup_dir):

if os.path.isfile("{}/backup_tags.txt".format(backup_dir)):

with open('{}/backup_tags.txt'.format(backup_dir), 'r') as bcktags:

from_file = bcktags.read()

column_names = "{0}\t{1}\t{2}\t{3}\t{4}\tTAG\n".format(

"Backup".ljust(19),

"Type".ljust(4),

"Status".ljust(2),

"Completion_time".ljust(19),

"Size")

extra_str = "{}\n".format("-"*(len(column_names)+21))

print(column_names + extra_str + from_file)

logger.info(column_names + extra_str + from_file)

else:

logger.warning("Could not find backup_tags.txt inside given backup directory. Can't print tags.")

print("WARNING: Could not find backup_tags.txt inside given backup directory. Can't print tags.")

开发者ID:ShahriyarR,项目名称:MySQL-AutoXtraBackup,代码行数:18,

示例13: read

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def read(self):

try:

from PIL import Image

from pyzbar.pyzbar import decode

decoded_data = decode(Image.open(self.filename))

if path.isfile(self.filename):

remove(self.filename)

try:

url = urlparse(decoded_data[0].data.decode())

query_params = parse_qsl(url.query)

self._codes = dict(query_params)

return self._codes.get("secret")

except (KeyError, IndexError):

Logger.error("Invalid QR image")

return None

except ImportError:

from ..application import Application

Application.USE_QRSCANNER = False

QRReader.ZBAR_FOUND = False

开发者ID:bilelmoussaoui,项目名称:Authenticator,代码行数:21,

示例14: convert_legacy_template

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def convert_legacy_template(path):

with open(path) as f:

ta = f.read().strip().split('\n\n')

groups = [parse_group(g) for g in ta]

data = {'groups': [group_to_dict(g) for g in groups]}

new_path = path[:-3] + 'yml'

warning = ''

if p.isfile(new_path):

new_path = path[:-4] + '-converted.yml'

warning = '(appended -converted to avoid collision)'

with open(new_path, 'w') as nf:

yaml.dump(data, nf, indent=4, default_flow_style=False)

os.remove(path)

print " - {} > {} {}".format(path, new_path, warning)

开发者ID:menpo,项目名称:landmarkerio-server,代码行数:21,

示例15: __init__

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def __init__(self, senna_path, operations, encoding='utf-8'):

self._encoding = encoding

self._path = path.normpath(senna_path) + sep

# Verifies the existence of the executable on the self._path first

#senna_binary_file_1 = self.executable(self._path)

exe_file_1 = self.executable(self._path)

if not path.isfile(exe_file_1):

# Check for the system environment

if 'SENNA' in environ:

#self._path = path.join(environ['SENNA'],'')

self._path = path.normpath(environ['SENNA']) + sep

exe_file_2 = self.executable(self._path)

if not path.isfile(exe_file_2):

raise OSError("Senna executable expected at %s or %s but not found" % (exe_file_1,exe_file_2))

self.operations = operations

开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:19,

示例16: build_vocab

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def build_vocab(tokens, cache='vocab.pkl', max_size=50000):

if not osp.isfile(cache):

counter = Counter(tokens)

words, _ = zip(*counter.most_common(max_size))

words = [PAD_TOKEN, UNK_TOKEN] + list(words)

token_to_index = dict(zip(words, range(len(words))))

if START_TOKEN not in token_to_index:

token_to_index[START_TOKEN] = len(token_to_index)

words += [START_TOKEN]

if END_TOKEN not in token_to_index:

token_to_index[END_TOKEN] = len(token_to_index)

words += [END_TOKEN]

with open(cache, 'wb') as f:

pickle.dump((token_to_index, words), f)

else:

with open(cache, 'rb') as f:

token_to_index, words = pickle.load(f)

return token_to_index, words

开发者ID:tofunlp,项目名称:lineflow,代码行数:21,

示例17: _load_options_from_inputs_spec

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def _load_options_from_inputs_spec(app_root, stanza_name):

input_spec_file = 'inputs.conf.spec'

file_path = op.join(app_root, 'README', input_spec_file)

if not op.isfile(file_path):

raise RuntimeError("README/%s doesn't exist" % input_spec_file)

parser = configparser.RawConfigParser(allow_no_value=True)

parser.read(file_path)

options = list(parser.defaults().keys())

stanza_prefix = '%s://' % stanza_name

stanza_exist = False

for section in parser.sections():

if section == stanza_name or section.startswith(stanza_prefix):

options.extend(parser.options(section))

stanza_exist = True

if not stanza_exist:

raise RuntimeError("Stanza %s doesn't exist" % stanza_name)

return set(options)

开发者ID:remg427,项目名称:misp42splunk,代码行数:22,

示例18: cvt_annotations

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def cvt_annotations(devkit_path, years, split, out_file):

if not isinstance(years, list):

years = [years]

annotations = []

for year in years:

filelist = osp.join(devkit_path, 'VOC{}/ImageSets/Main/{}.txt'.format(

year, split))

if not osp.isfile(filelist):

print('filelist does not exist: {}, skip voc{} {}'.format(

filelist, year, split))

return

img_names = mmcv.list_from_file(filelist)

xml_paths = [

osp.join(devkit_path, 'VOC{}/Annotations/{}.xml'.format(

year, img_name)) for img_name in img_names

]

img_paths = [

'VOC{}/JPEGImages/{}.jpg'.format(year, img_name)

for img_name in img_names

]

part_annotations = mmcv.track_progress(parse_xml,

list(zip(xml_paths, img_paths)))

annotations.extend(part_annotations)

mmcv.dump(annotations, out_file)

return annotations

开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:27,

示例19: load_ratings

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def load_ratings(file, sep='\t'):

"""

Load ratings from file

"""

if not isfile(file):

print "File %s does not exist." % file

sys.exit(1)

f = open(file, 'r')

# Filter based on movie ratings that have been seen (0 = not seen)

ratings = filter(lambda r: r[2] > 0, [parse_rating(line, '\t')[1] for line in f])

f.close()

if not ratings:

print "No ratings provided."

sys.exit(1)

else:

return ratings

开发者ID:oreillymedia,项目名称:Data_Analytics_with_Hadoop,代码行数:18,

示例20: process_images

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def process_images(*, path, outfile):

assert os.path.exists(path), "Input path doesn't exist"

files = [f for f in listdir(path) if isfile(join(path, f))]

print('Number of valid images is:', len(files))

imgs = []

for i in tqdm(range(len(files))):

img = scipy.ndimage.imread(join(path, files[i]))

assert isinstance(img, np.ndarray)

img = img.astype('uint8')

# HWC -> CHW, for use in PyTorch

img = img.transpose(2, 0, 1)

assert img.shape == (3, 64, 64)

imgs.append(img)

imgs = np.asarray(imgs).astype('uint8')

assert imgs.shape[1:] == (3, 64, 64)

np.save(outfile, imgs)

开发者ID:bayesiains,项目名称:nsf,代码行数:24,

示例21: init_pg

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def init_pg(pg_conn):

"""

Initialize pg database

"""

if pg_conn is None:

print('I am unable to connect to the database')

sys.exit(1)

cur = pg_conn.cursor()

sql_files = [f for f in listdir(SQL_SERVER_PATH) if isfile(join(SQL_SERVER_PATH, f))]

for sql_file in sql_files:

with open('%s/%s' % (SQL_SERVER_PATH, sql_file), 'r') as sql_model_file:

cur.execute(sql_model_file.read())

pg_conn.commit()

cur.close()

pg_conn.close()

开发者ID:nbeguier,项目名称:cassh,代码行数:20,

示例22: install_hg

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def install_hg(path):

""" Install hook in Mercurial repository. """

hook = op.join(path, 'hgrc')

if not op.isfile(hook):

open(hook, 'w+').close()

c = ConfigParser()

c.readfp(open(hook, 'r'))

if not c.has_section('hooks'):

c.add_section('hooks')

if not c.has_option('hooks', 'commit'):

c.set('hooks', 'commit', 'python:pylama.hooks.hg_hook')

if not c.has_option('hooks', 'qrefresh'):

c.set('hooks', 'qrefresh', 'python:pylama.hooks.hg_hook')

c.write(open(hook, 'w+'))

开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,

示例23: check_dependencies

​点赞 6

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def check_dependencies():

ettercap = popen('which ettercap').read().split("\n")

dhcpd = popen('which dhcpd').read().split("\n")

lista = [dhcpd[0],'/usr/sbin/airbase-ng',

ettercap[0]]

m = []

for i in lista:

m.append(path.isfile(i))

for k,g in enumerate(m):

if m[k] == False:

if k == 0:

print '[%s✘%s] DHCP not %sfound%s.'%(RED,ENDC,YELLOW,ENDC)

for c in m:

if c == False:

exit(1)

break

开发者ID:wi-fi-analyzer,项目名称:3vilTwinAttacker,代码行数:18,

示例24: isFirstRun

​点赞 5

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def isFirstRun(cls, path):

if not os.path.isdir(path):

os.mkdir(path)

return True

if not os.path.isfile(os.path.join(path, "files.xml")):

return True

return False

#

# Check if there are any updates available in Gurux www server.

#

# @param path

# Settings directory.

# Returns true if there are any updates available.

#

开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:17,

示例25: _test_files_and_attrs

​点赞 5

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def _test_files_and_attrs(calc, dtype_out):

assert isfile(calc.path_out[dtype_out])

assert isfile(calc.path_tar_out)

_test_output_attrs(calc, dtype_out)

开发者ID:spencerahill,项目名称:aospy,代码行数:6,

示例26: assert_calc_files_exist

​点赞 5

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def assert_calc_files_exist(calcs, write_to_tar, dtypes_out_time):

"""Check that expected calcs were written to files"""

for calc in calcs:

for dtype_out_time in dtypes_out_time:

assert isfile(calc.path_out[dtype_out_time])

if write_to_tar:

assert isfile(calc.path_tar_out)

else:

assert not isfile(calc.path_tar_out)

开发者ID:spencerahill,项目名称:aospy,代码行数:11,

示例27: tearDown

​点赞 5

# 需要导入模块: from os import path [as 别名]

# 或者: from os.path import isfile [as 别名]

def tearDown(self):

if isfile(self.tempfile):

remove(self.tempfile)

if isdir(self.tempdir):

rmtree(self.tempdir)

开发者ID:rrwen,项目名称:google_streetview,代码行数:7,

注:本文中的os.path.isfile方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值