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. Kinetic market finance. Kinetic market finance is a term that refers to the rapidly changing nature of the financial markets. In today’s fast-paced world, financial markets are constantly evolving and adapting to new technologies, regulations, and economic conditions. One of the key characteristics of kinetic market finance is its dynamic nature. Unlike traditional markets, which tend to be more stable and predictable, financial markets https://kinetic-market.pro/ are subject to sudden shifts and fluctuations. This can be due to a variety of factors, such as changes in government policy, shifts in consumer behavior, or unexpected events like natural disasters or geopolitical tensions. In this environment, investors and financial institutions must be agile and responsive in order to stay ahead of the curve. This requires a deep understanding of market trends, as well as the ability to quickly analyze and react to new information. In kinetic market finance, being able to adapt to changing conditions is crucial for success. Another important aspect of kinetic market finance is the role of technology. Advances in computing power, artificial intelligence, and data analytics have revolutionized the way financial markets operate. High-frequency trading algorithms can execute trades in milliseconds, and complex risk management models can help investors better understand and manage their portfolios. At the same time, the rise of cryptocurrencies and blockchain technology has introduced a new level of complexity to the financial markets. These digital assets operate outside of traditional banking systems and are subject to different regulations and risks. Understanding how to navigate this new landscape is essential for anyone looking to participate in kinetic market finance. Regulation also plays a key role in shaping the dynamics of financial markets. In the aftermath of the 2008 financial crisis, governments around the world implemented new regulations to prevent another meltdown. While these rules are intended to protect investors and prevent systemic risks, they can also have unintended consequences. For example, strict capital requirements can limit the ability of banks to lend money, which can impact economic growth. As a result, financial institutions must constantly monitor and adapt to changes in regulations in order to remain compliant and competitive. This requires a high level of vigilance and expertise, as even minor changes in the regulatory environment can have significant impacts on market dynamics. In conclusion, kinetic market finance is a complex and rapidly evolving field that requires a deep understanding of market trends, technology, and regulation. In order to succeed in this environment, investors and financial institutions must be agile, responsive, and proactive in their approach. By staying ahead of the curve and embracing innovation, they can navigate the challenges and opportunities of the modern financial markets.

发表评论

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