推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
collector
V2EX  ›  Python

python3.6 如何在程序中正确导入 dll

  •  
  •   collector · Apr 19, 2019 · 4745 views
    This topic created in 2600 days ago, the information mentioned may be changed or developed.

    小白请教一下,python3.6 如何正确的导入 dll 我要导入的这个 dll 是通达信的交易接口( TradeX2.dll ),需要通过登录下单,以前用的第一版没问题,现在更新了,就一直报错,第一版的时候可以直接 import Tradex 就可以了,但是现在不管是直接 import 还是使用 ctypes 库,都不能正常使用,而且按照开发文档写的程序还出现

    Traceback (most recent call last): File "C:/Users/intel/Desktop/TradeX2-标准版-20190402/TradeX2/tradex2Api.py", line 31, in logon TradeX2.OpenTdx() AttributeError: module 'TradeX2' has no attribute 'OpenTdx'

    的错误(要最新的文档结果还是给的旧版的..) 另外,使用 ctypes 库,vscode 和 pycharm 报的错都不一样。。。 (不会发图,希望有大佬可以帮助一下)

    17 replies    2021-01-04 10:16:16 +08:00
    ysc3839
        1
    ysc3839  
       Apr 19, 2019 via Android
    起码发代码来看看吧?没代码让人猜什么问题?
    collector
        2
    collector  
    OP
       Apr 19, 2019   ❤️ 1
    @ysc3839
    import sys

    sys.path.append(r'.\core_file')
    import msvcrt
    import TradeX
    import pandas as pd
    import datetime


    class Trade:
    def __init__(self, sHost="202.102.53.99", nPort=7718, sVersion="8.00", sBranchID=0, sAccountNo="",
    sTradeAccountNo="", sPassword="", sTxPassword=""):
    # 华泰证券账号
    self.sHost = sHost
    self.nPort = nPort
    self.sVersion = sVersion
    self.sBranchID = sBranchID
    self.sAccountNo = sAccountNo
    self.sTradeAccountNo = sTradeAccountNo
    self.sPassword = sPassword
    self.sTxPassword = sTxPassword

    def logon(self):
    try:
    TradeX.OpenTdx()
    client = TradeX.Logon(self.sHost, self.nPort, self.sVersion, self.sBranchID, self.sAccountNo,
    self.sTradeAccountNo, self.sPassword, self.sTxPassword)
    except TradeX.error as e:
    print("error:" + str(e))
    sys.exit(-1)

    errinfo = client.IsConnectOK()
    if errinfo != 1:
    print(errinfo)
    else:
    self.client = client
    print("登录成功")
    kunimi
        3
    kunimi  
       Apr 19, 2019 via Android
    嗯,华泰不是最近升级了通达信的接口么?还能用?
    collector
        4
    collector  
    OP
       Apr 19, 2019 via Android
    @kunimi 现在应该可以了,通达信那边好像也同步更新了
    eiun
        5
    eiun  
       Apr 23, 2019
    问一下 TradeX2.dll 在哪里找的,可以给我一份么
    lpdswing
        6
    lpdswing  
       Apr 23, 2019
    有啥问题,CDLL(path)就行了,还需要装 vs 运行环境,dll 依赖
    collector
        7
    collector  
    OP
       Apr 23, 2019
    @eiun 这个是通达信群里给的
    @lpdswing 感谢,已经搞好了
    eiun
        8
    eiun  
       Apr 26, 2019
    @collector 大佬求个群,最近在折腾这个,死活找不到新的这个文件
    atzhfy
        9
    atzhfy  
       May 2, 2019
    老大,怎么解决的发一下呗,我也是 py 的新手,那个 tradex 怎么用啊?
    atzhfy
        10
    atzhfy  
       May 2, 2019
    楼主,你就把这个代码修改什么地方告诉一下就行,谢谢
    atzhfy
        11
    atzhfy  
       May 2, 2019
    @collector 楼主,你能把这个代码修改什么地方告诉一下吗,谢谢
    atzhfy
        12
    atzhfy  
       May 3, 2019
    @eiun tradex2.dll 是收费的。
    collector
        13
    collector  
    OP
       May 6, 2019
    @eiun 876253162

    @atzhfy 什么也没改,就是让他们重新发了一份 python 的过来
    atzhfy
        14
    atzhfy  
       May 7, 2019
    @collector 你是说他们发了一个 3.6 版本的 python 吗?不是发的例子?
    collector
        15
    collector  
    OP
       May 16, 2019
    @atzhfy 他们给我发了一个 python 版的通达信过来,上次给我的是个 C++版的。。。python 版本最好用 3.6 的
    migtoloveyou
        16
    migtoloveyou  
       Jun 2, 2020
    想问一下这个 tradex2.dll 在哪里买?能给给渠道不?
    RingSunKaiya
        17
    RingSunKaiya  
       Jan 4, 2021
    情况:最近在看别人写的代码,发现该目录下只有 dll 和 py 文件,而 Py 文件的开头直接 Import 了这个 dll 文件,通过__file__方法,查看到导入包的路径和名称就是这个 py 文件同目录下的 dll 。
    问题:Python 可以直接 import 一个 dll 文件
    请问这个 dll 文件是如何生成的,是什么原理?
    是 Pythion 代码打包成 dll 还是用 C 写的 dll
    在网上查了以下资料 Python import 模块有四种方法
    1.使用 python 编写的.py 文件
    2.把一系列模块组织到一起的文件夹(注:文件夹下有一个__init__.py 文件,该文件夹称之为包)
    3.使用 C 编写并链接到 python 解释器的内置模块
    4.已被编译为共享库或 DLL 的 C 或 C++扩展

    Python 引用 dll 是使用的 ctypes
    但上面我看到的这个却很诡异,同博主的类似 直接 import 了 TradeX2
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5600 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 01:22 · PVG 09:22 · LAX 18:22 · JFK 21:22
    ♥ Do have faith in what you're doing.