From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.user Subject: Re: python-on-guile Date: Mon, 10 Feb 2020 15:46:30 +0100 Message-ID: References: <018d235b0c26bb87be28ddb1a2b26d42@selfhosted.xyz> <98c0afcebc4b6a584e7a576250b31256@selfhosted.xyz> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="75440"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "Stefan Israelsson Tampe " To: david larsson Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Feb 10 15:46:59 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j1AKx-000JWZ-2v for guile-user@m.gmane-mx.org; Mon, 10 Feb 2020 15:46:59 +0100 Original-Received: from localhost ([::1]:34626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1AKv-0007q4-MW for guile-user@m.gmane-mx.org; Mon, 10 Feb 2020 09:46:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59922) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1AKk-0007pv-EC for guile-user@gnu.org; Mon, 10 Feb 2020 09:46:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1AKh-0007hM-VI for guile-user@gnu.org; Mon, 10 Feb 2020 09:46:46 -0500 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:44232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j1AKh-0007gl-Kz for guile-user@gnu.org; Mon, 10 Feb 2020 09:46:43 -0500 Original-Received: by mail-wr1-x42e.google.com with SMTP id m16so8024992wrx.11 for ; Mon, 10 Feb 2020 06:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BFRQwE9AkeuCuEJdZi9uXA668cfJ78IgAbC15GkmdQE=; b=nQHGfCK0DOVhyJX9PkB2kIiTkRdUEY5PcN0dJqHUbznzV9Iig9eSgQbRyaetOD8PAk kI/0n83C2PoLxbS9glPeYLr5KfV51c9DAUXSTAyZExtU2JPvmS/B3SJWMZccSh/0LsUI cXxT9Ykujb0jN0llgRe2pYe2a/spdESpx8cHlhIknYHmhSJyx6Xg0910zSodnYU7kEuN MvHQ1TqU9bOcure3OZ0grFLcCGMne1hEbWIZNbfyKNuTNnxRG/+0kWHYJOhifP4/yVT2 uzTl+n35m0PHrcw6ognFo9Iy3DSyYD9TT342yO1+YEq/rtJX30NmYIbxhVHArdX91ftN GUDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BFRQwE9AkeuCuEJdZi9uXA668cfJ78IgAbC15GkmdQE=; b=QxIcXKOWcNAR0kwufUjm5Q6x79IfIPT3moOZR83+8bJXSrDqqb4mkuyha/HSxdEJgw VYfrhD8n8dBfZlr+BOrpLxyB6yReIUxqr89Wey7qUyWT1amkvcnNKfsbvLqJNd+68ELu xYuA1E/THI9OprnLh8SuEEyqzZmwpORb+2oxVR2ttpqntC6dB2qUMvh1K4jRfmiqU+iW cUAbjIRJbpLKUN2/aGgQJ/BX7LEn0AtykA1zPf15p9Q5if6FPxYlIhLCCgcx9glILw9V MV8PdniTfBcG3yyBdkNQMH4TVwGdE7hVhQS9AEDjgeV7hljVLvCPR8GFhriANhGGIu4H M1qQ== X-Gm-Message-State: APjAAAUr6cxVmwdS6aurZyxwE6XVZSLDh8SaJ/bdgaQajhAqWSCB56N+ Uqs8CBr0Mmzk8N2ktUA/w1+13DeIziCNdJF2urrt9p4/R+4= X-Google-Smtp-Source: APXvYqwKepxmj4TVMMGWzpzlqPAPxpfZQKEwCS7gijkS+dndAar9oxvCOa+zimu/vqP2bRNs3roYZEgT2wcbtq3QQmg= X-Received: by 2002:a05:6000:108b:: with SMTP id y11mr2403499wrw.187.1581346002088; Mon, 10 Feb 2020 06:46:42 -0800 (PST) In-Reply-To: <98c0afcebc4b6a584e7a576250b31256@selfhosted.xyz> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16150 Archived-At: >Im getting weird results when trying to output the base64 representation >>of a string, take btest.py: > #import sys > import base64 > def mybmethod(x): > mybytes = bytes(x, "utf-8") > encodedbytes = base64.b64encode(mybytes) > myb64string = str(encodedbytes, "utf-8") > return myb64string > #print(myb64string) > #mybmethod(sys.argv[1]) str(x,'utf-8') is supported but not bytes(x,'uft-8'). try to use x.encode('utf-8') in stead On Mon, Feb 10, 2020 at 1:14 PM david larsson wrote: > On 2020-02-09 21:36, Stefan Israelsson Tampe wrote: > > in sys that is > > > > On Sun, Feb 9, 2020 at 9:36 PM Stefan Israelsson Tampe > > wrote: > > > >> OKey, I changed the values from immutable lists to lists. > >> > > Great! > > >> On Sun, Feb 9, 2020 at 9:27 PM Stefan Israelsson Tampe > >> wrote: > >> > >> Note that a lot of things are untested because I'm alone on the > >> development. > > Ok, I understand. > > I haven't been able to build a recent version, but if you can share some > updated instructions, then I could perhaps help out with some occasional > testing. I have only managed to build from the old commit fc0d7a9 by > updating the current python-on-guile guix package locally. > > >> > >> netlib is not included, you can test to add the python module file > >> to a (language python module) directory > > What's been working for me so far is only (load "path/to/file.py") and > (load-compiled "path/to/file.go"). > > (use-modules (a b c)) did not work for me, except to load modules > already shipped with python-on-guile repo; (language python module > python) etc. > > >> > >> I have recently added much more of the python stdlib aka 3.7 but not > >> all. > >> > >> Not sure what you mean by .scm file and .py fle when it comes to > >> base64 > >> using that module in scheme gives > >> scheme@(guile-user)> (b64decode (b64encode "abc")) > >> $2 = b'abc' > >> scheme@(guile-user)> (b64decode (b64encode #(1 2 3))) > >> $3 = b'\x01\x02\x03' > >> > >> Which return a bytevector if you want a string back you need to > >> interpret the bytevector back to a string > > Im getting weird results when trying to output the base64 representation > of a string, take btest.py: > #import sys > import base64 > def mybmethod(x): > mybytes = bytes(x, "utf-8") > encodedbytes = base64.b64encode(mybytes) > myb64string = str(encodedbytes, "utf-8") > return myb64string > #print(myb64string) > #mybmethod(sys.argv[1]) > > and assume btest.scm using it with: > (add-to-load-path (dirname (current-filename))) > (use-modules (language python module python)) > (load "btest.py") > (define-public (mybmethodscm cmdline) > (display (mybmethod (cadr cmdline)))) > > With this it will not work to run the scheme file with > guile -e mybmethodscm btest.scm dfasdf > > The error I got indicated that btest.py uses the bytes procedure from > within python-on-guile instead of from the python3 base64 lib: > > ------------------- > > In > /home/user1/VirtualHome/src/code_guile/python-on-guile-test/btest.scm: > 18:11 4 (mybmethodscm _) > In btest.py: > 10:584 3 (_ "dfasdf" . _) > In oop/pf-objects.scm: > 584:15 2 (create-object _ _) > 567:11 1 (the-create-object _ _) > In language/python/bytes.scm: > 99:6 0 Exception thrown while printing backtrace: > Unbound slot in object Error while printing exception. > > language/python/bytes.scm:99:6: Wrong number of arguments to # 7f2bab5d4560 at language/python/bytes.scm:92:0 (self) | (self s)> > > ------------------- > > For a moment though, I could run: > > guile -e mybmethodscm btest.scm dfasdf | rev | base64 -d | rev > # gives: dfasdf > > which was also strange. > > >> > >> modules are a bit difficult as I use the guile module system and the > >> python modules are different. > >> So nested modules needs some work. The best is to test and see. > > Ok, got it! > > >> > >> I will look into the sys thingies > >> > >> Regards > >> Stefan > >> > >> On Sun, Feb 9, 2020 at 8:40 PM david larsson > >> wrote: > >> Thanks for your explanations, but unfortunately I still can't figure > >> out > >> how to use this except in the simplest of cases. > >> > >> I am using the guix package python-on-guile 0.1.0-3.00a51a2 - maybe > >> thats outdated? > >> > >> The simple things I have managed to do, are like: > >> > >> (add-to-load-path (dirname (current-filename))) > >> (load-compiled python-test.go) > >> > >> where python-test.go is compiled with: > >> > >> guild compile python-test.py --output=python-test.go > >> --from=python > >> > >> and contains simple things, like: > >> > >> f(s): > >> a = s + 1 > >> return a > >> > >> but if I add statements to python-test.py like: > >> > >> import netaddr > >> def myfun(a) > >> > >> > >> (netaddr is a module installed via: pip3 install --user netaddr) > >> > >> I receive an error about not finding the module. > >> > >> I am able to add only the modules which exist in the python-on-guile > >> > >> repo, like: > >> > >> import sys > >> import base64 > >> > >> but Im getting errors, for example Im not able to use things from > >> sys, > >> like: > >> > >> sys.path.append() > >> sys.path.insert(0, ) > >> > >> I was able to use some things from base64 but I only received weird > >> results when converting between bytevectors and strings between the > >> .scm > >> file and .py file. What works fine using python3 python-test.py do > >> not > >> usually work when passing either a bytevector or string to the same > >> go-compiled file from the .scm file using the python-code. Not sure > >> whether there's a problem using python3 vs python2 here? > >> > >> Essentially, what Im looking for is how to proceed if I want to use > >> modules installed via the pip package manager from guile, and what > >> paths > >> and imports I need to make, and how I might need to wrap them > >> correctly > >> in the scheme and python files to invoke a pip package procedure > >> from > >> guile. > >> > >> Best regards, > >> David > >> > >> On 2020-02-09 18:59, Stefan Israelsson Tampe wrote: > >>> I'm the author of that lib. > >>> > >>> 1) > >>> > >>> The main bindings are reachable through (language python module > >>> python) > >>> > >>> So you could now go ahead and do > >>>> (use-modules (language python module python)) > >>>> ;L python > >>> > >>> And you will get a python shell that works quite ok for one liners > >>> > >>> 2) > >>> > >>> If you write a module and place it in a/b/c.py > >>> you can use the classes and functions theirin by > >>> > >>> (use-modules (a b c)) > >>> > >>> 3) > >>> you can load a .py file as (i hope this work) > >>> (load "a.py") > >>> > >>> 4) > >>> If you place a module in (language python module a.py) you can > >> import > >>> ir as a usual mode as > >>>> from a import * > >>> > >>> The documentation is for the macro framework that enables you to > >> work > >>> with python classes and idioms like python iteration. > >>> > >>> Hope this helps > >>> /Stefan > >>> > >>> On Sun, Feb 9, 2020 at 6:31 PM david larsson > >>> wrote: > >>> > >>>> Hi everyone, > >>>> I am trying to wrap my head around how to use the python-on-guile > >>>> library, but Im struggling. Does anyone have example code that > >> might > >>>> > >>>> help, and which isn't too advanced? > >>>> > >>>> All tips and suggestions appreciated! > >>>> > >>>> Best regards, > >>>> David > >