python raspberry pi3 os.system synta error invalid syntax - syntax-error

This is my code. When I am running the code it says syntax error = invalid syntax, it sees "&" symbol as a invalid syntax.
enter code here
# -*- coding:utf-8 -*-
import RPi.GPIO as GPIO
import time
import os
buttonPin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonPin,GPIO.IN)
while True:
if (GPIO.input(buttonPin)):
os.system("fswebcam -r -d
/dev/video0/home/pi/webcam.jpg")
os.system("python /home/pi/mailgonder.py")

The code inside your while loop is not indented properly, and os.system arguments should be in quotes.

Related

Dynamic import in Jsonnet

I want to get input file in Jsonnet so the following is working great for me:
local input = import './inputfile.json';
Problem is that I want to pass the file name through the Jsonnet CLI and I tried to use --ext-str or TLA but in both cases im getting the following error:
computed imports are not allowed.
I also tried to use --ext-code like here:
jsonnet -J grafonnet-lib --ext-code input=(import "./inputfile.json") createDash.jsonnet
but then I'm getting:
zsh: unknown file attribute: i
Is there any solution for this problem?
I'm guessing zsh is gobbling up either the parenthesis or the double quotes. Drop both between single quotes.
➜ tmp jsonnet -J grafonnet-lib --ext-code input='(import "./inputfile.json")' createDash.jsonnet
{ }

Argparser interactive

My question is pretty straight,
Is argaparse has an option to prompt missed arguments just via input?
script.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('mode', metavar='', help='Set count of likes', default=49)
parser.add_argument('-n', '--number', metavar='', help='Set count of likes', default=49, required=True)
parser.add_argument('-f', '--frequency', metavar='', help='Set chance to like/dislike', default=70)
# Running it via bash:
$ python script.py
# argparse automaticaly checking that missed argument "--number" and asking it via input built-in
>>> (argparse) Missed required argument "number", please specify it now, number:

The PAKCS REPL consider something undefined, but the module defining it is loaded

The problem
My code includes a module called Tests which defines the following:
broken :: SetRBT Int
broken = insertRBT 1 $ emptySetRBT (<)
I can evaluate broken in the REPL:
All> broken
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>
I cannot, however, evaluate the RHS of broken's definition:
All> insertRBT 1 $ emptySetRBT (<)
PAKCS_Main_Exp.curry, line 3.18: Error:
Undefined type RedBlackTree.RedBlackTree
ERROR occurred during parsing!
All>
Or so I believed, until I tried attaching a type signature:
All> insertRBT 1 $ emptySetRBT (<) :: SetRBT Int
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>
I'm fine with having to attach type signatures when needed, or more generally, to do whatever the error messages suggest I should do. But how would I know to interpret the above error message as meaning "you've got to attach a type signature"? More generally, what does that type error even mean, given that (see below) RedBlackTree is loaded?
What I am loading
Each time I start PAKCS I run :l All. That loads a module which reads, in relevant part,
module All ( module M
) where
import FiniteMap as M
import SetRBT as M
import RedBlackTree as M
import Tests as M
That idiom lets me load all the things that I need (there are others) without producing a long prompt.
If I run :modules it looks like RedBlackTree should be defined:
All> :modules
Currently loaded modules:
All (loaded from ./.curry/pakcs/All.pl)
Prelude (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/Prelude.pl)
FiniteMap (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/FiniteMap.pl)
SetRBT (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/SetRBT.pl)
RedBlackTree (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/RedBlackTree.pl)
Tests (loaded from ./.curry/pakcs/Tests.pl)
All>
You must tell the interpreter to add referenced modules.
All> :add RedBlackTree SetRBT
... some messages ...
All SetRBT RedBlackTree> insertRBT 1 $ emptySetRBT (<)
and it will work.

pdfminer3k - pdf2txt.py error

I want to convert my pdf files to txt files and used pdfminer3k module & pdf2txt.py, however, I got an error.
pdf2txt.py -o file.txt -t tag file.pdf
This is my code at cmd screen.
Traceback (most recent call last):
File "C:\Python36\lib\site.py", line 67, in
import os
File "C:\Python36\lib\os.py", line 409
yield from walk(new_path, topdown, onerror, followlinks)
^
SyntaxError: invalid syntax
This is an error message that I got.
Could you help me to fix this problem??
Added for reference: Great resourse:
http://www.degeneratestate.org/posts/2016/Jun/15/extracting-tabular-data-from-pdfs/
The -t flag is the type of output. The options are text, tag, xml, and html.
Tag refers to generating a tag for xml. Replace tag with text in your command and try it.
The order of optional input also matters.
You also must invoke python, your command line does'nt know what import means, yet some of your environment seems to be setup. My example is for windows cmd from Anaconda3\Scripts directory. If your in juptyer notebook or a console, you should be able to run import pdf2txt with the .py
To setup your environment you need to append the os.path.append(yourpdfdirectory) otherwise file.pdf will not be found.
Try python pdf2txt.py -t text -o file.txt file.pdf
Or if you are brave...this is how to do programmatically. The trouble with xml is if you want to get the text, each character from xml tree is returned in an arbitrary order. You can get it to work but you need to build the string character by character which is not that hard, its just logically time consuming.
fp = open(filesin,'rb')
parser = PDFParser(fp)
doc = PDFDocument()
parser.set_document(doc)
doc.set_parser(parser)
doc.initialize('')
rsrcmgr = PDFResourceManager(caching=False)
laparams = LAParams(all_texts=True)
laparams.boxes_flow = -0.2
laparams.paragraph_indent = 0.2
laparams.detect_vertical = False
#laparams.heuristic_word_margin = 0.03
laparams.word_margin = 0.2
laparams.line_margin = 0.3
outfp = open(filesin+".out.tag" ,'wb')
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)
#process_pdf(rsrcmgr, device, pdfparse, pagenos,caching=c, check_extractable=True)
for p,page in enumerate(doc.get_pages()):
if p == 0: #temporary for page 1
interpreter.process_page(page)
layout = device.get_result()
alltextinbox = ''
#This is a rich environment so categorization of this object hierarchy is needed
for c,lt_obj in enumerate(layout):
#print(type(lt_obj),"This is type ",c,"th object on the ",p,"th page")
if isinstance(lt_obj,LTTextBoxHorizontal) or isinstance(lt_obj,LTTextBox) or isinstance(lt_obj,LTTextLine):
print("Type ,",type(lt_obj)," and text ..",lt_obj.get_text())
obj_textbox_line.update({lt_obj:lt_obj.get_text()})
elif p != 0:
pass
fp.close()
#print(obj_textbox_line)
#call the column finder here
#check_matching("example", "example1")
#text_doc_df = pd.DataFrame(obj_textbox_line,columns=['text'])
#print (text_doc_df)
pass
I'm working on a generic row/column matcher. If you don't want to bother, you can buy this software already for like 150 bucks for a pro converter.

Hello world does work in PE but not in PE64

I'm trying to kind of write my own x64 Hello world program in FASM on Windows
I tried to rewrite this version: How to write to the console in fasm?, to a x64 program like this:
format PE64
entry start
include 'win64a.inc'
section '.code' code readable executable
start:
push hello
call [printf]
pop rcx
push 0
call [ExitProcess]
section '.rdata' data readable
hello db 'Hello world!', 10, 0
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL', \
msvcrt,'msvcrt.dll'
import kernel, ExitProcess,'ExitProcess'
import msvcrt, printf, 'printf'
Now the problem is that this compiles fine, but when it is executed it doesn't print anything to the console.
Why does this not work, is printf of msvcrt silently incompatible with x64?
Have I overseen something?
Can someone tell me how to rewrite this for it to actually print "Hello world!"?