Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3332

Re: storing and reading notes in python

X-Received by 2002:ae9:f30f:: with SMTP id p15mr17396542qkg.178.1586803802428; Mon, 13 Apr 2020 11:50:02 -0700 (PDT)
X-Received by 2002:a25:abec:: with SMTP id v99mr28205639ybi.117.1586803802110; Mon, 13 Apr 2020 11:50:02 -0700 (PDT)
Path csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups fr.comp.lang.python
Date Mon, 13 Apr 2020 11:50:01 -0700 (PDT)
In-Reply-To <e411f9e8-bc83-401e-bac3-a47a08d74fe2@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info google-groups.googlegroups.com; posting-host=5.172.255.172; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host 5.172.255.172
References <e411f9e8-bc83-401e-bac3-a47a08d74fe2@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <c0edbba7-ae6c-4c54-8884-6357d8def85c@googlegroups.com> (permalink)
Subject Re: storing and reading notes in python
From john Stone <profesor.fir@gmail.com>
Injection-Date Mon, 13 Apr 2020 18:50:02 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Lines 76
Xref csiph.com fr.comp.lang.python:3332

Show key headers only | View raw


W dniu niedziela, 12 kwietnia 2020 15:43:22 UTC+2 użytkownik john Stone napisał:
> salute,
> 
> i can weakly read french (im learning it) but 
> i am unable  to write as for now, so maybe let me ask
> this question in english but you may answer
> in french 
> 
> im experienced in c but im total noob in python,
> maybe you can give me some hints
> 
> i write a irc bot (nicknamed 'minion') in python,
>  i want to make such  thing, if user will 
> send a line like
> 
> <fir> minion invite emily = hello emilly minion welcomes you
> 
> this line is stored in text file fir.txt as a line
> 
> invite emily = hello emilly minion welcomes you
> 
> then if i will send a line
> 
> <fir> minion invite emily
> then minion will send
> <minion> hello emilly minion welcomes you
> 
> obvoiusly linnes should be added and if same 'key' found 
> (in that case key is "invite emily") then it should be
> replaced
> 
> i also would want to mke it with some sense not to make 
> bery much disk reads maybe
> 
> i know python like 3 days and dont see how to do it yet
> 
> can someone help, tnx

ok i found it

   p = ircmsg.find(channel) 
    r = ircmsg.find('===') 
    if p!=-1 and r!=-1: 
      key = ircmsg[p+len(channel)+1:r] 
      value = ircmsg[r+1+1+1:] 
      say("przyjalem") 
      bot_memory[key]=value 
      save_bot_memory() 

    p = ircmsg.find(channel) 
    if p!=-1: 
      key = ircmsg[p+len(channel)+1:] 
      if key in bot_memory: 
        say(bot_memory[key]) 

where 


import json 

bot_memory = {'a': 'a', 
              'b': 'b', 
              'c': 'c'} 

f = open("bot_memory.json", 'r') 
bot_memory = json.load(f) 
f.close() 

def save_bot_memory(): 
    j = json.dumps(bot_memory) 
    f = open("bot_memory.json","w") 
    f.write(j) 
    f.close() 
    return 

i hope this is ok

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Find similar


Thread

storing and reading notes in python john Stone <profesor.fir@gmail.com> - 2020-04-12 06:43 -0700
  Re: storing and reading notes in python john Stone <profesor.fir@gmail.com> - 2020-04-13 11:50 -0700

csiph-web