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. Xrp passive income. XRP is a digital asset that has gained popularity in recent years as a potential source of passive income. As one of the top cryptocurrencies by market capitalization, XRP has attracted the attention of investors looking to diversify their portfolios and earn returns on their holdings. There are several ways to earn passive income with XRP, including staking, lending, and trading https://mysticfinance.org/ . Staking involves holding a certain amount of XRP in a designated wallet to support the network and validate transactions. In return, stakers are rewarded with additional XRP as a form of interest. This process helps to secure the network and maintain the integrity of the blockchain. Lending is another popular method for earning passive income with XRP. By lending XRP to other users on a decentralized platform, investors can earn interest on their holdings over time. This can be a lucrative way to generate additional income without the need for active trading or market speculation. Trading XRP can also be a profitable way to earn passive income, especially for experienced traders who understand market trends and price movements. By buying low and selling high, traders can make a profit on their XRP holdings over time. However, it’s important to note that trading comes with risks and requires a certain level of skill and knowledge to be successful. In addition to staking, lending, and trading, there are other ways to earn passive income with XRP. For example, some platforms offer rewards for participating in liquidity pools or providing liquidity to decentralized exchanges. By contributing XRP to these pools, investors can earn a share of the fees generated by trading activity on the platform. Overall, earning passive income with XRP can be a rewarding way to grow your wealth and diversify your investment portfolio. However, it’s important to do your research and understand the risks involved before getting started. By staying informed and making informed decisions, you can maximize your earnings and make the most of your investment in XRP. As with any investment, it’s important to consider your financial goals and risk tolerance before committing to a passive income strategy with XRP. While the potential for earning passive income with XRP is attractive, it’s essential to be mindful of market volatility and fluctuations in cryptocurrency prices. By taking a long-term approach and diversifying your investment portfolio, you can mitigate risks and maximize your returns over time. In conclusion, XRP offers a variety of opportunities for earning passive income, from staking and lending to trading and providing liquidity. By exploring these options and staying informed about market trends, you can take advantage of the potential for growth and earnings with XRP. Remember to do your due diligence and consult with a financial advisor if needed to make the most of your passive income strategy with XRP.

发表评论

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