Python学习之问题记录

一、__init__.py的作用

当需要加载自定义的目录下所有文件时,让该目录识别为package,则目录下需要有__init__.py 文件,另外在模糊加载时,也需要定义 例如: __all__ = [“Pack1Class”,”Pack1Class1″], 总结如下:

Python中package的标识,不能删除

定义__all__用来模糊导入

编写Python代码(不建议在__init__中写python模块,可以在包中在创建另外的模块来写,尽量保证__init__.py简单)

二、python中时间差中seconds和total_seconds

在python中经常会用到计算两个时间差,两个日期类型进行相减可以获取到时间差

经常会使用seconds来获取,其实seconds获取的是时间差的秒数,遗漏了天

seconds是获取时间部分的差值,而total_seconds()是获取两个时间之间的总差

import datetime

t1 = datetime.datetime.strptime("2016-08-24 10:30:00", "%Y-%m-%d %H:%M:%S")
t2 = datetime.datetime.strptime("2016-08-24 12:30:00", "%Y-%m-%d %H:%M:%S")

interval_time = (t2 - t1).seconds  # 输入的结果:7200
total_interval_time = (t2 - t1).total_seconds() # 输出结果也是: 7200

# 换一个方式
t1 = datetime.datetime.strptime("2016-08-24 10:30:00", "%Y-%m-%d %H:%M:%S")
t2 = datetime.datetime.strptime("2016-08-27 12:30:00", "%Y-%m-%d %H:%M:%S")

interval_time = (t2 – t1).seconds # 输入的结果:7200 total_interval_time = (t2 – t1).total_seconds() # 输出结果也是: 266400

三、 遍历数组获取索引下标

for i, one_js in enumerate(js_actions):

四、Python出现’ascii’ codec can’t encode characters…的解决方法

第一步,别忘了给顶行加上:
# -*- coding: utf-8 -*-
第二步,重新载入SYS模块并设置uft-8

         import sys
         reload(sys)
         sys.setdefaultencoding(‘utf-8’)

You May Also Like

About the Author: daidai5771

0 Comments

  1. Enosys dex fast transactions. Enosys dex is a revolutionary decentralized exchange that offers fast transactions and low fees. With Enosys dex, users can trade a wide range of cryptocurrencies quickly and securely, without the need for a middleman. One of the key features of Enosys dex is its fast transaction speeds. Unlike traditional exchanges that can take hours or even days to process transactions, Enosys dex https://enosys-global.com uses cutting-edge technology to ensure that trades are executed in a matter of seconds. This means that users can buy and sell cryptocurrencies quickly, allowing them to take advantage of market opportunities as soon as they arise. In addition to fast transaction speeds, Enosys dex also offers low fees. Traditional exchanges often charge high fees for trading, making it expensive for users to buy and sell cryptocurrencies. Enosys dex, on the other hand, charges minimal fees, allowing users to keep more of their profits. Another benefit of using Enosys dex is the security it provides. Centralized exchanges are vulnerable to hacking and fraud, putting users’ funds at risk. Enosys dex, on the other hand, is decentralized, meaning that users retain control of their funds at all times. This reduces the risk of theft and fraud, giving users peace of mind when trading cryptocurrencies. Enosys dex also offers a wide range of cryptocurrencies for trading. Whether you’re looking to buy Bitcoin, Ethereum, or any other popular cryptocurrency, you’ll find it on Enosys dex. This allows users to diversify their portfolios and take advantage of the many opportunities in the cryptocurrency market. Overall, Enosys dex is a game-changer in the world of cryptocurrency trading. With its fast transactions, low fees, and high level of security, it offers a superior trading experience to traditional exchanges. Whether you’re a seasoned trader or just getting started with cryptocurrency, Enosys dex is the perfect platform for buying and selling digital assets. If you’re tired of slow transactions, high fees, and security risks on traditional exchanges, it’s time to make the switch to Enosys dex. With its fast transactions, low fees, and high level of security, Enosys dex is the future of cryptocurrency trading. Join the revolution today and experience the benefits of decentralized trading for yourself.

发表评论

电子邮件地址不会被公开。 必填项已用*标注