How to use my own file as a default module in Python3? - python-3.4

import myfile
function1(2,3,4)
How can i use my file as a default module so that I can use it just by entering import myfilename without specifying
import sys
sys.path.insert(0 ,'/dir1/dir2')
import myfile
myfile.function1()

Related

Missing Jar Files for HelloGlobe (JogAmp)

I am trying to run the following example.
I get errors for the following lines
import framework.Semantic;
import glm.mat.Mat4x4;
import glm.vec._2.Vec2;
import glm.vec._3.Vec3;
import uno.debug.GlDebugOutput;
import uno.glsl.Program;
...
import static glm.GlmKt.glm;
import static uno.buffer.UtilKt.destroyBuffer;
import static uno.buffer.UtilKt.destroyBuffers;
It seems that I am missing some more jar files even though I successfully imported jogl-all.jar and gluegen-rt.jar
I tried searching mvnrepository but did not find the jars I was looking for. I am not using maven.

ModuleNotFoundError after build exe by pyinstaller

My project folder as below:
C:\HHS\Actions<mysomeclass>.py
C:\HHS\Configuration<mysomesetting>.txt
C:\HHS\Data<mysomedata>.txt
C:\HHS\Form<mysomeclass>.py
C:\HHS\Testcases<mysometestcaseclass>.py
C:\HHS\Labels\OCR\Tmp<somefile>.png
C:\HHS\main.py
C:\HHS<somebatfile>.bat
After build exe file by command: C:\HHS>pyinstaller --paths=C:\HHS\Actions;C:\HHS\Form;C:\HHS\Testcase main.py
I copy all folder Actions , Configuration, Data, Form , Testcase, all file .bat to C:\HHS\dist\main
After that I run file main.exe in dist\main. It overcome the previous issue (How to release an application write by Python (which has structure folder) to user) but I met the other issue as below:
C:\HHS\dist\main>main.exe
Which testcase do you want to test
1. Image Capture
2. Reset Base
3. OCRTestcase
4. USBOEMCommand (remember turn off Vietnamese)
Please enter that number : 1
C:\HHS\dist\main> py C:\HHS\dist\main\Testcases\ImageCapture.py
Traceback (most recent call last):
File "C:\HHS\dist\main\Testcases\ImageCapture.py", line 9, in <module>
from Actions.Config import Config
ModuleNotFoundError: No module name 'Actions'
This is my ImageCapture.py
import os
import serial
import time
import sys
import os
import logging
from Actions.Config import Config
import Actions.Common as Common
from datetime import datetime
from Actions import DBv2
from Actions.parselog2 import ParseLog
I know maybe how I import module Actions is not correct (although it can run successful by Pycharm) but not work after build exe. I don't know how to fix it. Please help me. Thanks alot.

Cannot import name 'operator'

I'm trying to create my first custom operator.
I have a airflow folder, a dags folder and a plugins folder.
Within the plugins folder I have the operators folder.
My operator is in the operators folder.
In my operators folder I have the following __init__.py file:
from operators.my_operator import MyOperator
__all__ = [
'MyOperator',
]
In my plugins folder I have the following __init__.py file:
from airflow.plugins_manager import AirflowPlugin
import operators
# Defining the plugin class
class NewOperator(AirflowPlugin):
name = "test_operator"
operators = [
operators.MyOperator
]
and then from my dag I'm calling my operator like this from airflow.operators import MyOperator
From the UI I see the error cannot import name 'MyOperator'
What's wrong?

How do I send an image using file open with python an telepot?

I'm trying to send an image from my drive to telegram using the method sendPhoto but I can't. Which is the trick ?
I'm using Python 3.6.7 My code is as follows:
import sys
import telepot
import aiohttp
import asyncio
import os
import time
bot = telepot.Bot('55615????:AA????)
bot.getMe()
id=32????
bot.sendPhoto(chatId, str(open("th-623777.jpg", os.O_RDONLY)) )

Qpython import modules in script

I have installed qpython for android, the problem is that when I install a module with pip in the python console I can import it properly, but not when I try to import it to a script.
in console ... I type:
>>>import requests
>>>requests
<module 'requests' from '/data/data/com.hipipal.qpyplus/.../__init__.py>
but in a script saved in scripts' folder, when I execute:
import requests
r = requests.get("http://www.google.com")
print r.text.encode('utf-8')
I get this:
import requests
ImportError: no module named requests
Can anybody help with that?
Thank you!
Add import site.
This works on my tablet:
#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import site
import requests
r = requests.get("http://www.google.com")
print r.text.encode('utf-8')

Resources