乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Jef!

[编程交流] opening file (strings) into li

[复制链接]

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-6 00:49:56 | 显示全部楼层
Ok, i've made some new tests today. Since I had points in my grades.txt, I find&replaced every points just to be sure they were not the cause of my issue. I even removed all the "-", to keep only letters, digits and parenthèses. It still didn't work. I've put the readit and the retrieving function in the same lsp file (singletest.lsp) containing
  1. (defun readit ( txt / des lst str )   (if       (and           (setq txt (findfile txt))           (setq des (open txt "r"))       )       (progn           (while (setq str (read-line des))               (setq lst (cons (read str) lst))           )           (close des)           (reverse lst)       )   ))(defun c:test ()(setq templst (readit "c:\\grades.txt")))
The file is not empty, and is in CADs support file search path list
  1. Command: (findfile "grades.txt")"\\\\server\\project\\_drawing dept\\jef\\script\\grades.txt"
I definitly got something tho. I tried as you said
  1. (read (strcat "(" importedgradelist ")"))
and it returned nothing (!) but reacted otherwise when I used the same function with a string I created.
 
Definitly am onto something here... OMGGGGGG  I just found the 2 problems.1 - in my grades.txt  I had a parentheses imbalance, 1 more opening than what I had closing. My baaaad, sooorry! Parentheses. If you don't like them, don't lisp! ok. still c:test didn't work..
 
2- (setq templst (readit "c:\\grades.txt")) seemed weird. Looking for it on my c: drive maybe? It is not, and the findfile does the job of finding it..  I tried (setq templst (readit "grades.txt")) and BAM! EVERYTHING worked!
 
-My car doesn't start, I've checked everything, battery, spark plugs, wires, air filter...
-It has gas?
-...
 
Now I only have to use lisp to put back the dots in my grades...piece of cake, maybe =D
thank you thank you thank you thank you thank you (inhaaaaaale) thank you thank you
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:55:05 | 显示全部楼层
Glad you were able to solve it Jef! - well done
 
My earlier example using "c:\\grades.txt" as an example filepath was perhaps confusing. Since the function uses findfile, the filepath argument may be an absolute filepath (e.g. "c:\\grades.txt"), relative filepath (e.g. "..\\grades.txt") or just a filename (e.g. "grades.txt") for which the function will search the working directory and SFSP.
 
Nevertheless, I'm sure you've learnt a great deal from the experience!
 
Lee
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:30 , Processed in 0.389004 second(s), 65 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表