I'm trying to make a discord bot that can read dates from a txt file on my device.
I've read the documentation and looked over similar posts, but I keep running into the same error. Just starting to learn python so please excuse any obvious mistakes/ strange formatting.
list = open("dates.txt","r")
list.seek(0)
var firstLine = file1.readline()
file1.close()
bot.sendMessage({
to: channelID,
message: firstLine
})
The error:
C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\bot.js:241
list = open("dates.txt","r")
^
ReferenceError: open is not defined
at DiscordClient.<anonymous> (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\bot.js:241:13)
at DiscordClient.emit (node:events:527:28)
at DiscordClient.handleWSMessage (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\discord.io\lib\index.js:1854:11)
at WebSocket.emit (node:events:527:28)
at Receiver.ontext (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\WebSocket.js:841:10)
at C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\Receiver.js:536:18
at Receiver.applyExtensions (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\Receiver.js:371:5)
at C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\Receiver.js:508:14
at Receiver.flush (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\Receiver.js:347:3)
at Receiver.finish (C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp\node_modules\ws\lib\Receiver.js:541:12)
PS C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp>
Might be useful to know
This bot is able to do other things like respond to commands
dates.txt exists in the same folder at C:\Users\My Laptop\Desktop\Discord Bots\HeadzUp
So it seems like I completely mashed up python and nodejs on accident.
Not quite sure what I was thinking but that was the issue.
Simple answer — don't mix nodejs and Python.
First of all you should avoid to redefine "list" as this is python keyword.
Second, the command is correct and the "open" keyword is built in in native python. So it should work.
This exact line works in my python environment (even when overwriting "list").
When you look at the end of the lines of the error message you can see the ".js" endings. This is hinting, that you somehow try to interpret python code with a javascript interpreter.
Maybe you should post some more information about your system and setup.
If you use a proper python3 interpreter your code should work.
Related
After booting SWUpdate yocto-generated image for the first time, executing swupdate results in error message:
Error parsing configuration file: 'globals' section missing, exiting.
I tried to strictly follow SWUpdate's documentation, but it gets short when it comes to yocto integration. I'm using meta-swupdate, meta-swupdate-boards, and meta-openembedded layers together with poky example repository all at Kirkstone tag, building via bitbake update-image and having modyfied local.conf as:
MACHINE ??= "raspberrypi4-64"
ENABLE_UART = "1"
RPI_USE_U_BOOT = "1"
IMAGE_FSTYPES = "wic ext4.gz"
PREFERRED_PROVIDER_u-boot-fw-utils = "libubootenv"
IMAGE_INSTALL:append = " swupdate"
Is there anything else I need to modify to generate the configuration file and be able to run SWUpdate binary properly?
Side question: In the documentation, it's recommended to append swupdate-www to achieve a better web server. However, if I append it, there is no swupdate-www binary inside the `/usr/bin' directory.
As with other recipes folders the recipes-support/swupdate/swupdate/raspberrypi4-64 folder was missing inside the meta-swupdate-boards layer. Therefore, an empty config file was always generated. After adding this folder and all related files, strongly inspired by raspberrypi3 folder, the error was gone and swupdate -h provided the expected output.
There was also one new error during build process thrown by yocto. It was related to missing systemd requirement and was solved by adding:
DISTRO_FEATURES_append = " systemd"
to local.conf
I tried install a package in python3 called Spexxy, using this:
pip3 install -r requirements.txt
python3 setup.py install
Using iPython in the shell, I can well import the package with import spexxy but when I try to use anything from the package, first I have to use an exclamation point before the command like for example !spexxytools grid create, otherwise I have the error:
File "<ipython-input-3-b744a07ba8b3>", line 1
spexxytools grid create --from-filename "lte(?P<Teff>\d{5})-(?P<logg>\d\.\d\d)(?P<FeH>[+-]\d\.\d)(\.Alpha=(?P<Alpha>[+-]\d\.\d\d))?\.PHOENIX"
^
SyntaxError: invalid syntax
But even when using the exclamation point, I now have the error:
File "/home/geoffrey/.local/bin/spexxy", line 4, in <module>
__import__('pkg_resources').run_script('spexxy==2.3', 'spexxy')
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1429, in run_script
.format(**locals()),
pkg_resources.ResolutionError: Script 'scripts/spexxy' not found in metadata at '/home/geoffrey/.local/lib/python3.6/site-packages/spexxy-2.3.dist-info'
Can you help me find what's wrong ?
setuptools.find_packages()
Packages are only recognized if they include an init.py file.
So if you put
...
packages = setuptools.find_packages(),
...
scripts=['scripts/spexxy'],
you will get this error.
To fix it either write spexxy as a module in your source or declare packages = manually instead of using find_packages().
Edit
spexxy setup.py is using
packages=find_packages(include=['spexxy', 'spexxy.*']),
scripts=['bin/spexxy', 'bin/spexxytools'],
But the bin directory is missing, so it should be:
packages=find_packages(include=['spexxy', 'spexxy.*', 'bin/*']),
scripts=['bin/spexxy', 'bin/spexxytools'],
I am running an existing C project, and having an error. It was used to have no problem, and I could not fix it even after reading similar issues and trying their solutions.
./autogen.sh
running: aclocal
' is already registered with AC_CONFIG_FILES.
/usr/src/ports/autoconf2.5/autoconf2.5-2.69-3.noarch/src/autoconf2.69/lib/autoconf/status.m4:288: AC_CONFIG_FILES is
expanded from...
configure.ac:890: the top level
autom4te-2.69: /usr/bin/m4 failed with exit status: 1
aclocal-1.15: error: echo failed with exit status: 1
error: while running 'aclocal'
As shown, the "autom4te-2.69" is failing, and I did not see any hints about what to do. I am using "Cygwin" on windows 10.
Any idea about how to fix this?
Thanks in advance!
I'm trying to initialize MongoDB from a tutorial and I had to write the following code:
mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.db --logappend --install
After I type it, it gives me the following error:
2018-02-27T21:11:20.978-0800 F CONTROL [main] Failed global initialization: FileNotOpen: Failed to open "C:\mongodb\log\mongo.db"
I don't have the directory "log" but nor does the guy in the tutorial, so I'm a little confused what might be the problem.
The problem was that I didn't have the files "log" and "data", and inside of data the file "db". You have to create those files manually in order for it to work.
I need to open my system monitor in the QTCreator, but when I try to do it I obtain the following error message:
/home/arakul/sysmon.sgrd: 2: /home/arakul/sysmon.sgrd: Syntax error: newline unexpected
I am trying to open the system monitor by using the following command:
execlp("/home/arakul/sysmon.sgrd","",NULL);
Sorry for my stupid question. I must use command ksysguard with parametrs.
system("ksysguard --desktopfile sysmon.sgrd");